form_validator는 Flutter 애플리케이션에서 폼 필드를 검증하기 위한 가볍고 직관적인 패키지입니다. 필수 항목, 이메일 형식, 길이 제약 및 사용자 정의 검증기와 같은 검증 규칙을 정의하기 위한 간단한 API를 제공합니다. Flutter의 FormField 위젯 전용으로 설계되어, 반복 코드 없이 사용자 입력이 지정된 기준을 충족하는지 확인하는 과정을 간소화합니다. 기존 폼과 원활하게 통합되며 Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원합니다.
사용 사례
사용자 등록 양식 검증
이메일과 비밀번호 입력 확인 중
필드 길이 요구 사항 보장
사용자 정의 검증 로직 구현
폼 상태 관리 간소화
주요 기능
최소한의 설정 및 구성
필수, 이메일, 길이 및 사용자 정의 검증기 지원
Flutter 내장 FormField 위젯과 호환됩니다
크로스 플랫폼 호환성
검증 실패 시 명확한 오류 메시지 표시
적합한 대상
초보자에서 중급자 수준의 Flutter 개발자
기본에서 중간 수준의 폼 검증이 필요한 앱
깨끗하고 가독성이 뛰어난 검증 코드를 우선시하는 프로젝트
고려 사항
기본 검증 시나리오에 한정됨
내장된 국제화 지원 없음
복잡한 중첩 폼 구조를 처리하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
form_validator
Simplest form validation for flutter form widgets.
Now you can use ValidationBuilder class to create validation logic. Here's simple validator that validates if input length is between 10 and 50 characters long.
final validate = ValidationBuilder().minLength(10).maxLength(50).build();
print(validate('test')); // Minimum length must be at least 10 charactersprint(validate('Hello World')); // null, means value is correct
Localization
You can set global locale using ValidationBuilder.setLocale(String localeName)
or you can also define locale on ValidationBuilder({ String localeName }) constructor.
ValidationBuilder.setLocale('en');
// will use *en* localizationValidationBuilder()
.minLength(5)
.build();
// will use *az* localizationValidationBuilder(localeName: 'az')
.minLength(5)
.build();
// will display custom messageValidationBuilder()
.minLength(5, 'Length < 5 😟')
.build();
Methods
.minLength(int minLength, [String message])
Validates if value length is not less than minLength.
.maxLength(int maxLength, [String message])
Validates if value length is not more than maxLength.
.email([String message])
Checks if value is an email address.
.phone([String message])
Checks if value is an phone number.
Note: This method might be changed in future.
.ip([String message])
Checks if value is correct IPv4 address.
.ipv6([String message])
Checks if value is correct IPv6 address.
.url([String message])
Checks if value is correct url address.
.match(String otherValue, [String message])
Checks if the value matches the specified otherValue. This can be used to validate if two input values are identical.
Validates if value passes any of left and right validations. If value doesn't passes any error message from right validation will be displayed (If reverse set to true message from left validation will be displayed).