validatestringformat - Validate String Format
Validates if a given string is in provided format. Formats are :URL, email, IBAN, BIC, VAT, ISBN and Regular Expresssion.
This function validates if a given string is in a provided format. The possible formats are URL, email, IBAN, BIC, VAT, ISBN, and Regular Expression. The function takes three inputs:
- "format": the format to validate the string, which is a required input. The possible values are vat, url, email, iban, bic, isbn, regex.
- "input": the string to be validated, which is a required input.
- "options": an optional object that contains additional options for certain formats, such as the 2-character country code for VAT validation.
Examples:
- A valid VAT: returns true for a valid VAT number, with the country code specified in the options.
- A valid Email: returns true for a valid email address.
- A valid IBAN: returns true for a valid IBAN number.
- A valid ISBN-10: returns true for a valid ISBN-10 number.
- A valid ISBN-13: returns true for a valid ISBN-13 number.
- A valid URL: returns true for a valid URL.
- A valid regex: returns true if the input string matches the provided regular expression.
- An invalid regex: returns false if the input string does not match the provided regular expression.
- A valid BIC: returns true for a valid BIC code.
format
string
Format to validate the string.
Possible values are: vat, url, email, iban, bic, isbn, regex
Example:
url
input
string
The string to be validated.
Example:
853746333B01
options
object
Additional options
Example:
{
"countryCode": "NL"
}
regex
string
Used to validate the input string. Only used if format is set to regex.
Example:
^[0-9]*$
countryCode
string
2 character country code. Only used if format is set to vat.
Possible values are: AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, EL, HU, IE, IT, LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE, XI
Example:
DE