Skip to content

Commit 74dbe1a

Browse files
add user information, network, and finance validators
1 parent ddd9cbd commit 74dbe1a

File tree

2 files changed

+64
-59
lines changed

2 files changed

+64
-59
lines changed

README-updated.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit ca
112112

113113
### Finance validators
114114

115-
- `FormBuilderValidators.bic()` - requires the field's to be a valid BIC.
116-
- `FormBuilderValidators.creditCardCVC()` - requires the field's value to be a valid credit card CVC number.
117-
- `FormBuilderValidators.creditCardExpirationDate()` - requires the field's value to be a valid credit card expiration date and can check if not expired yet.
118-
- `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
119-
- `FormBuilderValidators.iban()` - requires the field's to be a valid IBAN.
115+
- TODO `FormBuilderValidators.bic()` - requires the field's to be a valid BIC.
116+
- TODO `FormBuilderValidators.creditCardCVC()` - requires the field's value to be a valid credit card CVC number.
117+
- TODO `FormBuilderValidators.creditCardExpirationDate()` - requires the field's value to be a valid credit card expiration date and can check if not expired yet.
118+
- `Validators.creditCard()`: Checks if the field contains a valid credit card number.
119+
- TODO `FormBuilderValidators.iban()` - requires the field's to be a valid IBAN.
120120

121121
### Identity validators
122122

@@ -125,7 +125,6 @@ URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit ca
125125
- `FormBuilderValidators.firstName()` - requires the field's value to be a valid first name.
126126
- `FormBuilderValidators.lastName()` - requires the field's value to be a valid last name.
127127
- `FormBuilderValidators.passportNumber()` - requires the field's value to be a valid passport number.
128-
- `FormBuilderValidators.password()` - requires the field's to be a valid password that matched required conditions.
129128
- `FormBuilderValidators.ssn()` - requires the field's to be a valid SSN (Social Security Number).
130129
- `FormBuilderValidators.state()` - requires the field's value to be a valid state name.
131130
- `FormBuilderValidators.street()` - requires the field's value to be a valid street name.
@@ -134,14 +133,13 @@ URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit ca
134133

135134
### Network validators
136135

137-
- `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
138-
- `FormBuilderValidators.ip()` - requires the field's value to be a valid IP address.
139-
- `FormBuilderValidators.latitude()` - requires the field's to be a valid latitude.
140-
- `FormBuilderValidators.longitude()` - requires the field's to be a valid longitude.
141-
- `FormBuilderValidators.macAddress()` - requires the field's to be a valid MAC address.
142-
- `FormBuilderValidators.phoneNumber()` - requires the field's value to be a valid phone number.
143-
- `FormBuilderValidators.portNumber()` - requires the field's to be a valid port number.
144-
- `FormBuilderValidators.url()` - requires the field's value to be a valid URL.
136+
- `Validators.ip()`: Checks if the field contains a properly formatted `Internet Protocol` (IP) address.
137+
- `Validators.url()`: Checks if the field contains a properly formatted `Uniform Resource Locators` (URL).
138+
- TODO `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
139+
- TODO `FormBuilderValidators.latitude()` - requires the field's to be a valid latitude. - `FormBuilderValidators.longitude()` - requires the field's to be a valid longitude.
140+
- TODO `FormBuilderValidators.macAddress()` - requires the field's to be a valid MAC address.
141+
- TODO `FormBuilderValidators.phoneNumber()` - requires the field's value to be a valid phone number.
142+
- TODO `FormBuilderValidators.portNumber()` - requires the field's to be a valid port number.
145143

146144
### Numeric validators
147145

@@ -176,6 +174,13 @@ URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit ca
176174
- TODO `FormBuilderValidators.minWordsCount()` - requires the word count of the field's value to be greater than or equal to the provided minimum count.
177175
- TODO `FormBuilderValidators.singleLine()` - requires the field's string to be a single line of text.
178176

177+
### User Information validators
178+
179+
- `Validators.email()`: Checks if the field contains a valid email.
180+
- `Validators.password()`: Checks if the field contains a valid password. A password may require some
181+
conditions to be met in order to be considered as valid.
182+
- `Validators.phoneNumber()`: Checks if the field contains a valid phone number.
183+
179184
### Use-case validators
180185

181186
- `FormBuilderValidators.base64()` - requires the field's to be a valid base64 string.
@@ -185,7 +190,6 @@ URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit ca
185190
- `FormBuilderValidators.json()` - requires the field's to be a valid json string.
186191
- `FormBuilderValidators.languageCode()` - requires the field's to be a valid language code.
187192
- `FormBuilderValidators.licensePlate()` - requires the field's to be a valid license plate.
188-
- `FormBuilderValidators.uuid()` - requires the field's to be a valid uuid.
189193
- `FormBuilderValidators.vin()` - requires the field's to be a valid VIN number.
190194

191195
### Extension method validators

lib/src/form_builder_validators.dart

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,51 @@ final class Validators {
38533853
);
38543854

38553855
// User information validators
3856+
3857+
/// {@template validator_email}
3858+
/// A validator function that checks if a given string is a valid email address.
3859+
/// Uses either a custom or default RFC 5322 compliant regular expression for validation.
3860+
///
3861+
/// ## Parameters
3862+
/// - `regex` (`RegExp?`): Optional custom regular expression for email validation.
3863+
/// If not provided, uses a default RFC 5322 compliant pattern that supports:
3864+
/// - ASCII characters
3865+
/// - Unicode characters (including IDN domains)
3866+
/// - Special characters in local part
3867+
/// - Quoted strings
3868+
/// - Multiple dots
3869+
///
3870+
/// - `emailMsg` (`String Function(String input)?`): Optional custom error message
3871+
/// generator function that takes the invalid input and returns a custom error
3872+
/// message. If not provided, uses the default localized error text.
3873+
///
3874+
/// ## Returns
3875+
/// Returns a `Validator<String>` function that:
3876+
/// - Returns `null` if the email is valid
3877+
/// - Returns an error message string if the email is invalid
3878+
///
3879+
/// ## Examples
3880+
/// Basic usage with default settings:
3881+
/// ```dart
3882+
/// final emailValidator = email();
3883+
/// final result = emailValidator('user@example.com');
3884+
/// print(result); // null (valid email)
3885+
/// ```
3886+
///
3887+
/// Using custom regex and error message:
3888+
/// ```dart
3889+
/// final customValidator = email(
3890+
/// regex: RegExp(r'^[a-zA-Z0-9.]+@company\.com$'),
3891+
/// emailMsg: (input) => '$input is not a valid company email',
3892+
/// );
3893+
/// ```
3894+
/// {@endtemplate}
3895+
static Validator<String> email({
3896+
RegExp? regex,
3897+
String Function(String input)? emailMsg,
3898+
}) =>
3899+
val.email(regex: regex, emailMsg: emailMsg);
3900+
38563901
/// {@template validator_password}
38573902
/// Creates a composite validator for password validation that enforces multiple
38583903
/// password strength requirements simultaneously.
@@ -3959,50 +4004,6 @@ final class Validators {
39594004
}) =>
39604005
val.phoneNumber(regex: regex, phoneNumberMsg: phoneNumberMsg);
39614006

3962-
/// {@template validator_email}
3963-
/// A validator function that checks if a given string is a valid email address.
3964-
/// Uses either a custom or default RFC 5322 compliant regular expression for validation.
3965-
///
3966-
/// ## Parameters
3967-
/// - `regex` (`RegExp?`): Optional custom regular expression for email validation.
3968-
/// If not provided, uses a default RFC 5322 compliant pattern that supports:
3969-
/// - ASCII characters
3970-
/// - Unicode characters (including IDN domains)
3971-
/// - Special characters in local part
3972-
/// - Quoted strings
3973-
/// - Multiple dots
3974-
///
3975-
/// - `emailMsg` (`String Function(String input)?`): Optional custom error message
3976-
/// generator function that takes the invalid input and returns a custom error
3977-
/// message. If not provided, uses the default localized error text.
3978-
///
3979-
/// ## Returns
3980-
/// Returns a `Validator<String>` function that:
3981-
/// - Returns `null` if the email is valid
3982-
/// - Returns an error message string if the email is invalid
3983-
///
3984-
/// ## Examples
3985-
/// Basic usage with default settings:
3986-
/// ```dart
3987-
/// final emailValidator = email();
3988-
/// final result = emailValidator('user@example.com');
3989-
/// print(result); // null (valid email)
3990-
/// ```
3991-
///
3992-
/// Using custom regex and error message:
3993-
/// ```dart
3994-
/// final customValidator = email(
3995-
/// regex: RegExp(r'^[a-zA-Z0-9.]+@company\.com$'),
3996-
/// emailMsg: (input) => '$input is not a valid company email',
3997-
/// );
3998-
/// ```
3999-
/// {@endtemplate}
4000-
static Validator<String> email({
4001-
RegExp? regex,
4002-
String Function(String input)? emailMsg,
4003-
}) =>
4004-
val.email(regex: regex, emailMsg: emailMsg);
4005-
40064007
// Finance validators
40074008
/// {@template validator_credit_card}
40084009
/// A validator function for credit card number validation that supports major card

0 commit comments

Comments
 (0)