1 | import { buildMessage, ValidateBy } from '../common/ValidateBy';
|
2 | import matchesValidator from 'validator/lib/matches';
|
3 | export const IS_MILITARY_TIME = 'isMilitaryTime';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function isMilitaryTime(value) {
|
9 | const militaryTimeRegex = /^([01]\d|2[0-3]):?([0-5]\d)$/;
|
10 | return typeof value === 'string' && matchesValidator(value, militaryTimeRegex);
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export function IsMilitaryTime(validationOptions) {
|
17 | return ValidateBy({
|
18 | name: IS_MILITARY_TIME,
|
19 | validator: {
|
20 | validate: (value, args) => isMilitaryTime(value),
|
21 | defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a valid representation of military time in the format HH:MM', validationOptions),
|
22 | },
|
23 | }, validationOptions);
|
24 | }
|
25 |
|
\ | No newline at end of file |