The library serve a collection of validator functions.
npm install @baloise/web-app-validatorsisCustom(validatorFn: BalValidatorFn) => BalValidatorFn
Returns true if the value date is before the given date.
BalValidators.isCustom((value) => value > 2)(3) // trueisBefore(date: any) => BalValidatorFn
Returns true if the value date is before the given date
BalValidators.isBefore('2000-01-02')('2000-01-01') // true
BalValidators.isBefore(new Date(2020, 0, 2))(new Date(2020, 0, 1)) // trueisAfter(date: any) => BalValidatorFn
Returns true if the value date is before the given date
BalValidators.isAfter('2000-01-01')('2000-01-02') // true
BalValidators.isAfter(new Date(2020, 0, 1))(new Date(2020, 0, 2)) // trueisDate() => BalValidatorFn
Returns true if the value is valid date
BalValidators.isDate()('2000-01-02') // true
BalValidators.isDate()(new Date(2000, 0, 1)) // trueisMin(min: number) => BalValidatorFn
Returns true if the number is bigger or equal than the min number
BalValidators.isMin(10)(10) // true
BalValidators.isMin(10)(11) // true
BalValidators.isMin(10)(9) // falseisMax(max: number) => BalValidatorFn
Returns true if the number is smaller or equal than the max number
BalValidators.isMax(10)(10) // true
BalValidators.isMax(10)(9) // true
BalValidators.isMax(10)(11) // falseisNumber() => BalValidatorFn
Returns true if the number is valid
BalValidators.isNumber()(10) // true
BalValidators.isNumber()('a') // falseisMonetaryNumber() => BalValidatorFn
Returns true if the value is a valid formatted number
BalValidators.isMonetaryNumber()(10) // true
BalValidators.isMonetaryNumber()(`1'000.99`) // true
BalValidators.isMonetaryNumber()(`a`) // falsematchesRegex(regex: RegExp) => BalValidatorFn
Returns true if the value matches the regex
BalValidators.matchesRegex(new RegExp('^\\d+$'))('1') // trueisEmail() => BalValidatorFn
Returns true if the value matches the regex
BalValidators.isEmail()('peter@baloise.ch') // trueisPhone() => BalValidatorFn
Returns true if the value matches the regex
BalValidators.isPhone()('123 456 78 90') // trueisRequired() => BalValidatorFn
Returns true if the value is a non-empty value
BalValidators.isRequired()('foo') // true
BalValidators.isRequired()('') // falseisRequiredTrue() => BalValidatorFn
Returns true if the value is true. This validator is commonly used for required checkboxes.
BalValidators.isRequiredTrue()(true) // true
BalValidators.isRequiredTrue()('') // falseisMinLength(minLength: number) => BalValidatorFn
Returns true if the string is bigger or equal than the min length
BalValidators.isMinLength(3)('123') // true
BalValidators.isMinLength(3)('12') // falseisMaxLength(maxLength: number) => BalValidatorFn
Returns true if the string is smaller or equal than the max length
BalValidators.isMaxLength(3)('123') // true
BalValidators.isMaxLength(3)('1234') // false