Skip to content

Commit 608fa12

Browse files
committed
Fix tests
1 parent 4f3a54a commit 608fa12

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

lib/src/form_builder_validators.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ class FormBuilderValidators {
323323
String? errorText,
324324
}) =>
325325
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
326-
!isCreditCardExpirationDate(valueCandidate!) &&
327-
!isNotExpiredCreditCardDate(valueCandidate)
326+
!isCreditCardExpirationDate(valueCandidate!) ||
327+
!isNotExpiredCreditCardDate(valueCandidate!)
328328
? errorText ??
329329
FormBuilderLocalizations.current.creditCardExpiredErrorText
330330
: null;
@@ -520,10 +520,10 @@ class FormBuilderValidators {
520520
}) =>
521521
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
522522
specialCharLength(valueCandidate!) >= atLeast
523-
? errorText ??
523+
? null
524+
: errorText ??
524525
FormBuilderLocalizations.current
525-
.containsSpecialCharErrorText(atLeast)
526-
: null;
526+
.containsSpecialCharErrorText(atLeast);
527527

528528
/// [FormFieldValidator] that requires the field's value to contain an amount of uppercase characters.
529529
static FormFieldValidator<String> hasUppercaseChars({
@@ -532,10 +532,10 @@ class FormBuilderValidators {
532532
}) =>
533533
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
534534
uppercaseCharLength(valueCandidate!) >= atLeast
535-
? errorText ??
535+
? null
536+
: errorText ??
536537
FormBuilderLocalizations.current
537-
.containsUppercaseCharErrorText(atLeast)
538-
: null;
538+
.containsUppercaseCharErrorText(atLeast);
539539

540540
/// [FormFieldValidator] that requires the field's value to contain an amount of lowercase characters.
541541
static FormFieldValidator<String> hasLowercaseChars({
@@ -544,10 +544,10 @@ class FormBuilderValidators {
544544
}) =>
545545
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
546546
lowercaseCharLength(valueCandidate!) >= atLeast
547-
? errorText ??
547+
? null
548+
: errorText ??
548549
FormBuilderLocalizations.current
549-
.containsLowercaseCharErrorText(atLeast)
550-
: null;
550+
.containsLowercaseCharErrorText(atLeast);
551551

552552
/// [FormFieldValidator] that requires the field's value to contain an amount of numeric characters.
553553
static FormFieldValidator<String> hasNumericChars({
@@ -556,7 +556,7 @@ class FormBuilderValidators {
556556
}) =>
557557
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
558558
numberCharLength(valueCandidate!) >= atLeast
559-
? errorText ??
560-
FormBuilderLocalizations.current.containsNumberErrorText(atLeast)
561-
: null;
559+
? null
560+
: errorText ??
561+
FormBuilderLocalizations.current.containsNumberErrorText(atLeast);
562562
}

lib/src/utils/validators.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ RegExp _creditCard = RegExp(
1212
r'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$',
1313
);
1414

15-
RegExp _phoneNumber =
16-
RegExp(r'^(\+?\d{0,1})?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}$');
15+
RegExp _phoneNumber = RegExp(r'^\+?(\d{1,4}[\s-])?(?!0+\s+,?$)\d{1,15}$');
1716

1817
RegExp _creditCardExpirationDate = RegExp(r'^[0-1][0-9]/\d{2}$');
1918

@@ -248,7 +247,7 @@ bool isDate(String str) {
248247

249248
/// check if the string is a valid phone number
250249
bool isPhoneNumber(String str) {
251-
return _phoneNumber.hasMatch(str);
250+
return _phoneNumber.hasMatch(str.replaceAll(' ', ''));
252251
}
253252

254253
/// check if the string is a valid credit card expiration date

test/form_builder_validators_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,13 +624,13 @@ void main() {
624624
'FormBuilderValidators.conditional',
625625
(WidgetTester tester) => testValidations(tester, (context) {
626626
final validator = FormBuilderValidators.conditional(
627-
(value) => value == 'test',
628-
FormBuilderValidators.required(),
627+
(value) => value != null,
628+
FormBuilderValidators.hasUppercaseChars(atLeast: 3),
629629
);
630630
// Pass
631-
expect(validator('test'), isNotNull);
631+
expect(validator('HELLO'), isNull);
632632
// Fail
633-
expect(validator('not_test'), isNull);
633+
expect(validator('hello'), isNotNull);
634634
}),
635635
);
636636

0 commit comments

Comments
 (0)