Skip to content

Commit 6653240

Browse files
committed
Format
1 parent 476e04a commit 6653240

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/src/form_builder_validators.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,8 @@ class FormBuilderValidators {
10171017
String? errorText,
10181018
}) =>
10191019
(valueCandidate) => !values.contains(valueCandidate)
1020-
? errorText ?? FormBuilderLocalizations.current.containsElementErrorText
1020+
? errorText ??
1021+
FormBuilderLocalizations.current.containsElementErrorText
10211022
: null;
10221023

10231024
/// [FormFieldValidator] that requires the field's value to be a valid IBAN.
@@ -1049,5 +1050,4 @@ class FormBuilderValidators {
10491050
valueCandidate?.isEmpty != false || !isISBN(valueCandidate!)
10501051
? errorText ?? FormBuilderLocalizations.current.isbnErrorText
10511052
: null;
1052-
10531053
}

lib/src/utils/validators.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ bool isNotExpiredCreditCardDate(String str) {
308308
return true;
309309
}
310310

311+
/// check if the string is a color
312+
/// * [formats] is a list of color formats to check
311313
bool isColorCode(String value,
312314
{List<String> formats = const ['hex', 'rgb', 'hsl']}) {
313315
if (formats.contains('hex') && _hex.hasMatch(value)) {
@@ -359,10 +361,12 @@ bool isAlphabetical(String value) {
359361
return _alphabetical.hasMatch(value);
360362
}
361363

364+
/// check if the string is a valid UUID
362365
bool isUUID(String value) {
363366
return _uuid.hasMatch(value);
364367
}
365368

369+
/// check if the string is valid JSON
366370
bool isJSON(String value) {
367371
try {
368372
jsonDecode(value);
@@ -372,6 +376,7 @@ bool isJSON(String value) {
372376
}
373377
}
374378

379+
/// check if the string is a valid latitude
375380
bool isLatitude(String value) {
376381
value = value.replaceAll(',', '.');
377382

@@ -382,6 +387,7 @@ bool isLatitude(String value) {
382387
return latitude >= -90 && latitude <= 90;
383388
}
384389

390+
/// check if the string is a valid longitude
385391
bool isLongitude(String value) {
386392
value = value.replaceAll(',', '.');
387393

@@ -392,6 +398,7 @@ bool isLongitude(String value) {
392398
return longitude >= -180 && longitude <= 180;
393399
}
394400

401+
/// check if the string is a valid base64 string
395402
bool isBase64(String value) {
396403
try {
397404
base64Decode(value);
@@ -401,6 +408,7 @@ bool isBase64(String value) {
401408
}
402409
}
403410

411+
/// check if the string is a valid file path
404412
bool isFilePath(String value) {
405413
return _filePath.hasMatch(value);
406414
}
@@ -415,6 +423,7 @@ bool isEvenNumber(String value) {
415423
return number % 2 == 0;
416424
}
417425

426+
/// check if the string is a valid MAC address
418427
bool isMACAddress(String value) {
419428
final splitChar = value.contains(':') ? ':' : '-';
420429
final parts = value.split(splitChar);
@@ -430,6 +439,7 @@ bool isMACAddress(String value) {
430439
return true;
431440
}
432441

442+
/// check if the string is a valid IBAN
433443
bool isIBAN(String iban) {
434444
iban = iban.replaceAll(' ', '').toUpperCase();
435445

@@ -454,6 +464,7 @@ bool isIBAN(String iban) {
454464
return remainder == 1;
455465
}
456466

467+
/// check if the string is a valid BIC
457468
bool isBIC(String bic) {
458469
bic = bic.replaceAll(' ', '').toUpperCase();
459470

@@ -464,9 +475,10 @@ bool isBIC(String bic) {
464475
return _bic.hasMatch(bic);
465476
}
466477

478+
/// check if the string is a valid ISBN
467479
bool isISBN(String isbn) {
468-
isbn = isbn.replaceAll('-', '').replaceAll(' ', ''); // Remove hyphens and spaces
469-
480+
isbn = isbn.replaceAll('-', '').replaceAll(' ', '');
481+
470482
if (isbn.length == 10) {
471483
if (!RegExp(r'^\d{9}[\dX]$').hasMatch(isbn)) return false;
472484

0 commit comments

Comments
 (0)