What are JavaScript validators in Magento 2?

- Fire development, Magento 2

Magento 2 Development

In case you are looking for Magento 2 JavaScript validators, below we have them listed in a table.

'

allow-container-className

alphanumeric

Letters, numbers, spaces, or underscores only

credit-card-types

Please enter a valid credit card number.

dateITA

Please enter a correct date

dateNL

Vul hier een geldige datum in.

email2

Please enter a valid email address.

greater-than-equals-to

Please enter a value greater than or equal to %s.

integer

A positive or negative non-decimal number please

ipv4

Please enter a valid IP v4 address.

ipv6

Please enter a valid IP v6 address.

less-than-equals-to

Please enter a value less than or equal to %s.

letters-only

Letters only please

letters-with-basic-punc

Letters or punctuation only please

max-words

Please enter {0} words or less.

min-words

Please enter at least {0} words.

mobileUK

Please specify a valid mobile number

no-whitespace

No white space please

not-negative-amount

Please enter positive number in this field.

pattern

Invalid format.

phoneUK

Please specify a valid phone number

phoneUS

Please specify a valid phone number

range-words

Please enter between {0} and {1} words.

required-dropdown-attribute-entry

Admin is a required field in the each row.

required-entry

This is a required field.

required-file

Please select a file.

required-if-all-sku-empty-and-file-not-loaded

Enter valid SKU key

required-if-not-specified

This is a required field.

required-if-specified

This is a required field.

required-number

Please enter a valid number in this field.

required-number-if-specified

Please enter a valid number.

required-text-swatch-entry

Swatch and Admin are the required fields in the each row

required-visual-swatch-entry

Admin is a required field in the each row.

stripped-min-length

Please enter at least {0} characters

time1

Please enter a valid time, between 00:00 and 23:59

time12h

Please enter a valid time, between 00:00 am and 12:00 pm

url2

Please enter a valid URL.

validate-admin-password

Please enter 7 or more characters, using both numeric and alphabetic.

validate-ajax-error

validate-alpha

Please use letters only (a-z or A-Z) in this field.

validate-alphanum

Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.

validate-alphanum-with-spaces

Please use only letters (a-z or A-Z), numbers (0-9) or spaces only in this field.

validate-cc-cvn

Please enter a valid credit card verification number.

validate-cc-exp

Incorrect credit card expiration date.

validate-cc-number

Please enter a valid credit card number.

validate-cc-type

Credit card number does not match credit card type.

validate-cc-type-select

Card type does not match credit card number.

validate-cc-ukss

Please enter issue number or start date for switch/solo card type.

validate-clean-url

Please enter a valid URL. For example http://www.example.com or www.example.com.

validate-code

Please use only letters (a-z), numbers (0-9) or underscore (_) in this field, and the first character should be a letter.

validate-cpassword

Please make sure your passwords match.

validate-css-length

Please input a valid CSS-length (Ex: 100px, 77pt, 20em, .5ex or 50%).

validate-currency-dollar

Please enter a valid $ amount. For example $100.00

validate-data

Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in this field, and the first character should be a letter.

validate-date

Please enter a valid date.

validate-date-au

Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.

validate-date-range

Make sure the To Date is later than or the same as the From Date.

validate-digits

Please enter a valid number in this field.

validate-digits-range

The value is not within the specified range.

validate-email

Please enter a valid email address (Ex: johndoe@domain.com).

validate-emailSender

Please enter a valid email address (Ex: johndoe@domain.com).

validate-emails

Please enter valid email addresses, separated by commas. For example, johndoe@domain.com, johnsmith@domain.com.

validate-fax

Please enter a valid fax number (Ex: 123-456-7890).

validate-greater-than-zero

Please enter a number greater than 0 in this field.

validate-identifier

Please enter a valid URL Key (Ex: “example-page”, “example-page.html” or “anotherlevel/example-page

validate-item-quantity

validate-length

Maximum length of this field must be equal or less than %1 symbols.

validate-new-password

Please enter 6 or more characters. Leading or trailing spaces will be ignored.

validate-no-empty

Empty Value.

validate-no-html-tags

HTML tags are not allowed.

validate-not-negative-number

Please enter a number 0 or greater in this field.

validate-number

Please enter a valid number in this field.

validate-number-range

The value is not within the specified range.

validate-one-required

Please select one of the options above.

validate-one-required-by-name

Please select one of the options.

validate-optional-datetime

The field isn\’t complete.

validate-password

Please enter 6 or more characters. Leading or trailing spaces will be ignored.

validate-per-page-value

Please enter a valid value from list

validate-per-page-value-list

Please enter a valid value, ex: 10,20,30

validate-phoneLax

lease enter a valid phone number. For example (123) 456-7890 or 123-456-7890.

validate-phoneStrict

Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.

validate-range

The value is not within the specified range.

validate-required-datetime

This is a required field.

validate-select

Please select an option.

validate-ssn

Please enter a valid social security number (Ex: 123-45-6789).

validate-state

Please select State/Province.

validate-street

Please use only letters (a-z or A-Z), numbers (0-9), spaces and “#” in this field.

validate-url

Please enter a valid URL. Protocol is required (http://, https:// or ftp://).

validate-zero-or-greater

Please enter a number 0 or greater in this field.

validate-zip-international

Please enter a valid zip code.

validate-zip-us

Please enter a valid zip code (Ex: 90602 or 90602-1234).

vinUS

The specified vehicle identification number (VIN) is invalid.

zip-range

Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx

Source

More tips from the cookbook

'