Address
Validating address is rather simple but time consuming task, valid8r address 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 address: string = "123 Main St., Apt #4B";
// The configuration can be defaulted globally
valid8r.address(input, {
safe: false, // boolean
minLen: 5, // number
maxLen: 255, // number
allowedSpChars: ["#", ",", "."], // string[]
properCapitalization: true, // boolean
noConsecutiveSpaces: 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 address = "123 Main St., Apt #4B";
// The configuration can be defaulted globally
valid8r.address(input, {
safe: false, // boolean
minLen: 5, // number
maxLen: 255, // number
allowedSpChars: ["#", ",", "."], // string[]
properCapitalization: true, // boolean | Every letter of first word should be capitalized
noConsecutiveSpaces: true, // boolean | No spaces one after another
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