Phone
Validating phone numbers is rather simple but time consuming task, valid8r phone validators provides a handful of options to best suit your validation requirements
import valid8r from '@c4code/valid8r';Configuration Options
import valid8r from '@c4code/valid8r';
const input: string = "+1 1234567890";
// The configuration can be defaulted globally
valid8r.phone(input, {
safe: false, // boolean
allowDashes: false, // boolean
allowParentheses: false, // boolean
minLen: 10, // number
maxLen: 15, // number
allowedCountryCodes: ["*"], // string[] | defaults to every country code
requireCountryCode: true, // boolean
throwErrorsAs: "throw-all", // "throw-first" | "throw-last" | "throw-all",
/*
"throw-first" => Throws or returns the first error encountered,
"throw-last" => Throws or returns the last error encountered,
"throw-all" => Throws or returns all errors in a Array of string
*/
}); // the second argument is optionalimport valid8r from '@c4code/valid8r';
const input = "+1 1234567890";
// The configuration can be defaulted globally
valid8r.phone(input, {
safe: false, // boolean
allowDashes: false, // boolean
allowParentheses: false, // boolean
minLen: 10, // number
maxLen: 15, // number
allowedCountryCodes: ["*"], // string[] | defaults to every country code
requireCountryCode: true, // boolean
throwErrorsAs: "throw-all", // "throw-first" | "throw-last" | "throw-all",
/*
"throw-first" => Throws or returns the first error encountered,
"throw-last" => Throws or returns the last error encountered,
"throw-all" => Throws or returns all errors in a Array of string
*/
}); // the second argument is optionalBasic Usage
Safe handling
Error Messages
Error Message Options
Last updated