Skip to content

Commit 410698f

Browse files
committed
Check credit card
1 parent 6f493e1 commit 410698f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit ca
4949
Available built-in validators include:
5050

5151
- `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
52-
- `FormBuilderValidators.creditCardExpirationDate()` - requires the field's value to be a valid credit card expiration date.
53-
- `FormBuilderValidators.creditCardExpirationDateNotExpired()` - requires the field's value to be aa valid credit card expiration date and not be expired.
52+
- `FormBuilderValidators.creditCardExpirationDate()` - requires the field's value to be a valid credit card expiration date and can check if not expired yet.
5453
- `FormBuilderValidators.creditCardCVC()` - requires the field's value to be a valid credit card CVC number.
5554
- `FormBuilderValidators.colorCode()` - requires the field's value to be a valid color code.
5655
- `FormBuilderValidators.date()` - requires the field's value to be a valid date string.

lib/src/form_builder_validators.dart

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,24 +308,17 @@ class FormBuilderValidators {
308308

309309
/// [FormFieldValidator] that requires the field's value to be a valid credit card expiration date.
310310
static FormFieldValidator<String> creditCardExpirationDate({
311+
bool checkForExpiration = true,
311312
String? errorText,
312313
}) =>
313314
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
314315
!isCreditCardExpirationDate(valueCandidate!)
315316
? errorText ??
316317
FormBuilderLocalizations.current.creditCardExpirationDateErrorText
317-
: null;
318-
319-
/// [FormFieldValidator] that requires the field's value to be a valid credit card expiration date and not expired.
320-
static FormFieldValidator<String> creditCardExpirationDateNotExpired({
321-
String? errorText,
322-
}) =>
323-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
324-
!isCreditCardExpirationDate(valueCandidate!) ||
325-
!isNotExpiredCreditCardDate(valueCandidate!)
326-
? errorText ??
327-
FormBuilderLocalizations.current.creditCardExpiredErrorText
328-
: null;
318+
: (checkForExpiration && !isNotExpiredCreditCardDate(valueCandidate!))
319+
? errorText ??
320+
FormBuilderLocalizations.current.creditCardExpiredErrorText
321+
: null;
329322

330323
/// [FormFieldValidator] that requires the field's value to be a valid credit card CVC.
331324
static FormFieldValidator<String> creditCardCVC({

0 commit comments

Comments
 (0)