JAVASCRIPT
Validation Utilities
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Function name | Description |
---|---|
.ascii(s, [options]) | Checks if a field only contains only ASCII alphanumeric characters. |
.checkCharacterGroups(s, [groups]) | Checks if a field has the required groups. |
.codPostal(cp1, [cp2], [returnBothResults]) | Validates if a zip code is valid in Portugal |
.createRegExp(groups) | Creates a regular expression for several character groups. |
.email(email) | Checks if an email address is valid |
.getEANCheckDigit(digits) | Get the check digit of an EAN code without a check digit. |
.isAOPhone(phone) | Checks if a phone is valid in Angola |
.isCVPhone(phone) | Checks if a phone is valid in Cabo Verde |
.isColor(str) | Checks if a string is a valid color |
.isCreditCard(num, creditCardType) | Checks if a number is of a specific credit card type |
.isDate(format, dateStr) | Checks if a date is valid in a given format |
.isEAN(code, [eanType]) | Validate an EAN barcode string. |
.isIP(value, ipType) | Checks if the value is a valid IP. |
.isMZPhone(phone) | Checks if a phone is valid in Mozambique |
.isPTPhone(phone) | Checks if a phone is valid in Portugal |
.isPhone(phone, [countryCode]) | Checks if a number is a phone number. |
.isPortuguesePhone(phone) | Alias function for isPTPhone |
.isTLPhone(phone) | Checks if a phone is valid in Timor |
.latin1(s, [options]) | Checks if a field only contains latin-1 alphanumeric characters. |
.number(numb, [options]) | Checks if a number is a valid |
.unicode(s, [options]) | Checks if a field contains unicode printable characters. |
.url(url, [full]) | Checks if an url is valid |
Checks if a field only contains only ASCII alphanumeric characters.
Takes options for allowing singleline whitespace, cross-line whitespace and punctuation.
s
The validation stringoptions
{}Optional configuration object. See createRegexpCode
Checks if a field has the required groups.
s
The validation stringgroups
{}What groups are included. See `createRegExp`Code
Validates if a zip code is valid in Portugal
cp1
If passed alone, it's the full postal code. If passed with `cp2`, it's the first fragment of the zip code, which should have 4 numeric digits.cp2
Second fragment of the zip code, which should have 3 numeric digits.returnBothResults
When given both `cp1` and `cp2`, return an array `[Boolean, Boolean]`, indicating which of these were valid. For example `[true, true]` means both were valid, while `[true, false]` means `cp1` was valid, and `cp2` was invalid.Code
Creates a regular expression for several character groups.
groups
Groups to build regular expressions for. Possible keys are:Checks if an email address is valid
Code
Get the check digit of an EAN code without a check digit.
digits
The remaining digits, out of which the check digit is calculated.Checks if a phone is valid in Angola
phone
Phone number to be checkedCode
Checks if a phone is valid in Cabo Verde
phone
Phone number to be checkedCode
Checks if a string is a valid color
str
Color string to be checkedCode
Checks if a number is of a specific credit card type
num
Number to be validatescreditCardType
Credit card type or list of types. See _creditCardSpecs for the list of supported values.Code
Checks if a date is valid in a given format
format
Format defined in _dateParsersdateStr
Date stringCode
Validate an EAN barcode string.
code
The code containing the EANeanType
'ean-13'Select your EAN type. Can be 'ean-8' or 'ean-13'Checks if the value is a valid IP.
value
Value to be checkedipType
Type of IP to be validated. The values are: ipv4, ipv6. By default is ipv4.Code
Checks if a phone is valid in Mozambique
phone
Phone number to be checkedCode
Checks if a phone is valid in Portugal
phone
Phone number to be checkedCode
Checks if a number is a phone number.
This method validates the number in all country codes available the ones set in the second param
phone
Phone number to validatecountryCode
Country code or array of countries to validateCode
Alias function for isPTPhone
phone
Phone number to be checkedChecks if a phone is valid in Timor
phone
Phone number to be checkedCode
Checks if a field only contains latin-1 alphanumeric characters.
Takes options for allowing singleline whitespace, cross-line whitespace and punctuation.
s
The validation stringoptions
{}Optional configuration object. See createRegexpCode
Checks if a number is a valid
numb
The numberoptions
Further optionsoptions.decimalSep
'.'Allow decimal separator.options.thousandSep
","Strip this character from the number.options.negative
falseAllow negative numbers.options.decimalPlaces
nullMaximum number of decimal places. Use `0` for an integer number.options.max
nullMaximum numberoptions.min
nullMinimum numberoptions.returnNumber
falseWhen this option is `true`, return the number itself when the value is valid.Code
Checks if a field contains unicode printable characters.
s
The validation stringoptions
{}Optional configuration object. See createRegexpChecks if an url is valid
url
URL to be checkedfull
If true, validates a full URL (one that should start with 'http')Code