-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from DarDevDuck/master
Feature: Validation Message with complex Validations
- Loading branch information
Showing
6 changed files
with
69 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { email, telephoneNumber } from '../../utils/regex'; | ||
export const econtextValidationRules = { | ||
blur: { | ||
default: value => { | ||
return { isValid: value && value.length > 0, errorMessage: true }; | ||
}, | ||
telephoneNumber: value => { | ||
return { | ||
isValid: value && telephoneNumber.test(value) && (value.length === 10 || value.length === 11), | ||
errorMessage: 'voucher.econtext.telephoneNumber.invalid' | ||
}; | ||
}, | ||
shopperEmail: value => { | ||
return { | ||
isValid: email.test(value), | ||
errorMessage: true | ||
}; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import { email, telephoneNumber } from '../../../utils/regex'; | ||
import { unformatDate } from '../FormFields/InputDate/utils'; | ||
|
||
const isDateOfBirthValid = value => { | ||
if (!value) return false; | ||
const rawValue = unformatDate(value); | ||
const ageDiff = Date.now() - Date.parse(rawValue); | ||
const age = new Date(ageDiff).getFullYear() - 1970; | ||
return age >= 18; | ||
}; | ||
|
||
export const personalDetailsValidationRules = { | ||
blur: { | ||
default: value => value && value.length > 0, | ||
default: value => { | ||
const isValid: boolean = value && value.length > 0; | ||
return { isValid: isValid, errorMessage: true }; | ||
}, | ||
dateOfBirth: value => { | ||
if (!value) return false; | ||
const rawValue = unformatDate(value); | ||
const ageDiff = Date.now() - Date.parse(rawValue); | ||
const age = new Date(ageDiff).getFullYear() - 1970; | ||
return age >= 18; | ||
return { isValid: isDateOfBirthValid(value), errorMessage: 'dateOfBirth.invalid' }; | ||
}, | ||
telephoneNumber: value => { | ||
return { isValid: telephoneNumber.test(value), errorMessage: true }; | ||
}, | ||
telephoneNumber: value => telephoneNumber.test(value), | ||
shopperEmail: value => email.test(value) | ||
shopperEmail: value => { | ||
return { isValid: email.test(value), errorMessage: true }; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters