Validator reference
Every rule you can put in data-validation. The core set needs no module;
everything else names the module that provides it.
Core validators no module
Available as soon as the plugin loads.
required
A value must be given. Works on text inputs, textareas, selects, checkboxes and radio groups.
<input name="name" data-validation="required">
<input type="checkbox" name="terms" data-validation="required">
<select name="plan" data-validation="required">
<option value="">Choose a plan</option>
<option>Free</option>
</select>length
Constrains how long the value is. On a <select multiple> it counts selected options, and on a file input it counts files.
| Attribute | Purpose |
|---|---|
data-validation-length | min4, max100, or a range such as 50-200. Required. |
<input data-validation="length" data-validation-length="min4">
<input data-validation="length" data-validation-length="max100">
<input data-validation="length" data-validation-length="50-200">
<!-- At least two options selected -->
<select multiple data-validation="length" data-validation-length="min2">…</select>An email address. Quoted local parts are supported; a quoted section followed by unquoted text is rejected, as RFC 5322 requires.
<input name="email" data-validation="email">url
An absolute URL. Accepts userinfo, ports, IPv6 literals and internationalised domains.
<input name="site" data-validation="url">domain
A bare domain name such as example.com, without a scheme or path. Internationalised xn-- top level domains are accepted.
<input name="domain" data-validation="domain">number
A numeric value. Integers only unless you widen it, with optional range and step constraints.
| Attribute | Purpose |
|---|---|
data-validation-allowing | Comma separated: float, negative, number, and range[min;max]. |
data-validation-decimal-separator | Per field override of the separator, usually ,. |
data-validation-step | The value must be a multiple of this. |
With , as the decimal separator a dot can only be a thousands separator, so it has to fall on a group boundary. 1.234.567,89 is accepted; 1.0236 is not, because that dot is being used as a decimal point.
<!-- Whole numbers -->
<input data-validation="number">
<!-- Decimals, including negatives -->
<input data-validation="number" data-validation-allowing="float,negative">
<!-- Bounded -->
<input data-validation="number" data-validation-allowing="range[1;100]">
<input data-validation="number" data-validation-allowing="range[0.05;0.5],float">
<!-- Comma as the decimal separator -->
<input data-validation="number" data-validation-allowing="float"
data-validation-decimal-separator=",">alphanumeric
Letters a–z and digits only. Additional characters can be allowed explicitly.
| Attribute | Purpose |
|---|---|
data-validation-allowing | Extra characters to permit, e.g. -_. Regex metacharacters are escaped for you. |
For letters outside a–z, use letternumeric from the security module.
<input data-validation="alphanumeric">
<input data-validation="alphanumeric" data-validation-allowing="-_">custom
Test the value against your own regular expression.
| Attribute | Purpose |
|---|---|
data-validation-regexp | The pattern. Required — an empty pattern is rejected rather than silently passing. |
<input data-validation="custom" data-validation-regexp="^([a-z]+)$">date
A calendar date. Leap years and month lengths are checked, and a format need not carry every unit.
| Attribute | Purpose |
|---|---|
data-validation-format | Defaults to the dateFormat option (yyyy-mm-dd). Any arrangement works: dd/mm/yyyy, mm/yyyy. |
data-validation-require-leading-zero | "false" accepts 2000-1-1 as well as 2000-01-01. |
<input data-validation="date">
<input data-validation="date" data-validation-format="dd/mm/yyyy">
<input data-validation="date" data-validation-format="mm/yyyy">
<input data-validation="date" data-validation-require-leading-zero="false">checkbox_group
How many boxes in a group sharing a name must be ticked. Only the first checkbox needs the attributes.
| Attribute | Purpose |
|---|---|
data-validation-qty | min1, max3, or a range such as 1-4. Required. |
<input type="checkbox" name="topics[]" data-validation="checkbox_group"
data-validation-qty="1-3">
<input type="checkbox" name="topics[]">
<input type="checkbox" name="topics[]">Security security module
Passwords, payment details, spam and server-side checks.
strength rescored in 3.0
Password strength on a 0–3 scale, following NIST SP 800-63B rev 4: driven by length, not by character composition.
| Attribute | Purpose |
|---|---|
data-validation-strength | Minimum acceptable score, 1–3. Defaults to 2. |
Only length an attacker actually has to guess counts. Runs (aaaa) and sequences (abcd, 9876) are discounted from the third character on, and passwords that dominate breach corpora score zero however long they are — Password1! and letmein123 included.
The old scoring awarded points for mixed case, digits and symbols, so P@ss1! rated 3 of 3 while a sixteen-character lowercase password rated 2. Both now score 0 and 3 respectively. Re-check any form relying on a particular level — see the upgrade guide.
<input type="password" data-validation="strength" data-validation-strength="2">breached new in 3.0 network request
Rejects passwords that appear in the Have I Been Pwned corpus. Opt-in, and it calls out to the network.
| Attribute | Purpose |
|---|---|
data-validation-breach-url | Override the range endpoint to self-host it. |
data-validation-debounce | Milliseconds to wait before calling out. Defaults to 500. |
The password never leaves the browser. Only the first five hex characters of its SHA-1 are sent; the service returns every suffix sharing that prefix and the match is made locally — the k-anonymity model the API is built around. On the wire it is nothing more than GET /range/5BAA6.
If the service cannot be reached the value is allowed and a warning is logged. An outage of a third-party service should not become an outage of your form, and your other password rules still apply. Requires a secure context for crypto.subtle.
<input type="password" data-validation="strength breached">confirmation
Two fields must match — the classic "repeat your password" check.
| Attribute | Purpose |
|---|---|
data-validation-confirm | The name of the field this one has to match. |
<input type="password" name="pw" data-validation="strength">
<input type="password" name="pw_confirm"
data-validation="confirmation" data-validation-confirm="pw">creditcard
A card number: length for the accepted brands, digits only, and a Luhn checksum.
| Attribute | Purpose |
|---|---|
data-validation-allowing | Comma separated brands, e.g. visa,mastercard,amex. Omit to accept any 13–19 digit number. |
<input name="card" data-validation="creditcard"
data-validation-allowing="visa,mastercard,amex">cvv
The card security code. Length follows the brands the form accepts — four digits when it is American Express only, three otherwise.
Put it in the same form as the creditcard field; that is how it learns which brands are in play.
<input name="card" data-validation="creditcard" data-validation-allowing="amex">
<input name="cvv" data-validation="cvv">server
Hands the value to your backend and uses the response. Asynchronous, so submission waits for the answer.
| Attribute | Purpose |
|---|---|
data-validation-url | Endpoint to call. Required. |
data-validation-param-name | Parameter name for the value. Defaults to the field's name. |
data-validation-req-params | Extra parameters, as a JSON object. |
data-validation-debounce | Milliseconds to wait before calling out. Defaults to 500. |
Respond with JSON: {"valid": true}, or {"valid": false, "message": "Already taken"} to supply your own text.
<input name="username" data-validation="server"
data-validation-url="/api/username-available">letternumeric
Letters in any alphabet, plus digits. The Unicode-aware counterpart to alphanumeric.
| Attribute | Purpose |
|---|---|
data-validation-allowing | Extra characters to permit. |
<input data-validation="letternumeric" data-validation-allowing="-_">spamcheck
A simple question-and-answer honeypot for casual bot traffic.
| Attribute | Purpose |
|---|---|
data-validation-captcha | The expected answer. |
<label>What is 2 + 3?</label>
<input data-validation="spamcheck" data-validation-captcha="5">recaptcha network request
Google reCAPTCHA v2. The widget is rendered for you.
| Attribute | Purpose |
|---|---|
data-validation-recaptcha-sitekey | Your site key. Required. |
data-validation-recaptcha-theme | light or dark. |
data-validation-recaptcha-size | normal or compact. |
data-validation-recaptcha-type | image or audio. |
<div data-validation="recaptcha"
data-validation-recaptcha-sitekey="your-site-key"></div>complexity deprecated
Composition rules — so many uppercase letters, so many digits, and so on.
| Attribute | Purpose |
|---|---|
data-validation-require-uc-letter | Minimum uppercase letters. |
data-validation-require-lc-letter | Minimum lowercase letters. |
data-validation-require-numeral | Minimum digits. |
data-validation-require-special-char | Minimum special characters. |
data-validation-require-length | Minimum total length. |
These are exactly the composition rules NIST SP 800-63B rev 4 retired, because they push people toward short predictable passwords. Prefer strength, ideally with breached. It still works, and logs a warning, for sites bound to a policy they do not control.
Date and time date module
time
A time of day in hh:mm.
<input data-validation="time">birthdate
A date that is neither in the future nor implausibly far in the past.
| Attribute | Purpose |
|---|---|
data-validation-format | Defaults to the dateFormat option. |
data-validation-age-range | Permitted age span, e.g. 18-120. Defaults to 0-124. |
Fires an ageCalculated event on the field with the computed age.
<input data-validation="birthdate" data-validation-age-range="18-120">Files file module
These read the selected file through the File API, so nothing is uploaded to check it.
size
Caps the size of the chosen file.
| Attribute | Purpose |
|---|---|
data-validation-max-size | e.g. 2M, 500K. Required. |
<input type="file" data-validation="size" data-validation-max-size="2M">mime
Restricts the file by reported MIME type.
| Attribute | Purpose |
|---|---|
data-validation-allowing | Comma separated types, e.g. image/png,image/jpeg. |
<input type="file" data-validation="mime"
data-validation-allowing="image/png,image/jpeg">extension
Restricts the file by filename extension.
| Attribute | Purpose |
|---|---|
data-validation-allowing | Comma separated extensions, e.g. jpg,png,pdf. |
<input type="file" data-validation="extension"
data-validation-allowing="jpg,png,pdf">dimension
Constrains the pixel dimensions, or the aspect ratio, of a chosen image.
| Attribute | Purpose |
|---|---|
data-validation-dimension | e.g. min200x200, max1024x768, 200x200-800x600. |
data-validation-ratio | Required aspect ratio, e.g. 16:9. |
Fires an imageValidation event once the image has been measured.
<input type="file" data-validation="dimension"
data-validation-dimension="min200x200">
<input type="file" data-validation="dimension"
data-validation-ratio="16:9">Browser constraints native module
Bridges the HTML5 Constraint Validation API.
native new in 3.0
Hands the field's own HTML constraints to the browser and reports what ValidityState says.
Answers required, type, min, max, step, pattern, minlength and maxlength from the browser rather than from a regular expression. Messages still come from your configured language, falling back to the browser's own localised text.
Loading the module also mirrors every result onto the element with setCustomValidity(), so element.validity, form.checkValidity() and :user-invalid agree with your data-validation rules. See the module notes.
<input type="email" required data-validation="native">
<input type="number" min="10" max="20" step="2" data-validation="native">
<input pattern="[A-Z]{3}" data-validation="native">Banking sepa module
iban
An International Bank Account Number, including its checksum.
<input data-validation="iban">bic
A Bank Identifier Code, also known as a SWIFT code.
<input data-validation="bic">sepa
An IBAN that belongs to a country inside the SEPA area.
<input data-validation="sepa">Colours color module
Each accepts data-validation-allow-transparent="true" to permit the keyword transparent.
hex
A hexadecimal colour, #fff or #ffffff.
<input data-validation="hex">rgb
An rgb(r, g, b) colour.
<input data-validation="rgb">rgba
An rgba(r, g, b, a) colour.
<input data-validation="rgba">hsl
An hsl(h, s%, l%) colour.
<input data-validation="hsl">hsla
An hsla(h, s%, l%, a) colour.
<input data-validation="hsla">Location location module
Also provides input suggestions for countries and US states.
country
A country name, in English.
<input data-validation="country">federatestate
A US state or a German federal state.
<input data-validation="federatestate">longlat
A longitude and latitude pair.
<input data-validation="longlat">Country-specific formats
National identifiers, phone numbers and tax references.
swesec
A Swedish personal identity number. sweden module
| Attribute | Purpose |
|---|---|
data-validation-use-hyphen | Require the hyphenated form. |
Fires a genderDerived event with the gender encoded in the number.
<input data-validation="swesec">swephone
A Swedish telephone number. sweden module
<input data-validation="swephone">swemobile
A Swedish mobile number. sweden module
<input data-validation="swemobile">swecounty
An existing Swedish county. sweden module
<input data-validation="swecounty">swemunicipality
An existing Swedish municipality. sweden module
<input data-validation="swemunicipality">ukvatnumber
A UK VAT registration number. uk module
<input data-validation="ukvatnumber">uknin
A UK National Insurance number. uk module
<input data-validation="uknin">ukutr
A UK Unique Taxpayer Reference. uk module
<input data-validation="ukutr">cpf
A Brazilian CPF number. brazil module
<input data-validation="cpf">cep
A Brazilian CEP postal code. brazil module
<input data-validation="cep">brphone
A Brazilian telephone number. brazil module
<input data-validation="brphone">plpesel
A Polish PESEL personal identity number. poland module
<input data-validation="plpesel">plnip
A Polish NIP VAT identification number. poland module
<input data-validation="plnip">plregon
A Polish REGON business identity number. poland module
<input data-validation="plregon">Conditional rules logic module
The logic module does not add validators. It adds attributes that decide whether the rules already on a field should run at all.
<!-- Only validated when #other-country has a value -->
<input name="region" data-validation="required"
data-validation-depends-on="other-country">
<!-- Only when that field holds a specific value -->
<input name="vat" data-validation="required"
data-validation-depends-on="country"
data-validation-depends-on-value="SE">
<!-- Optional as soon as one of these has been answered -->
<input name="phone" data-validation="required"
data-validation-optional-if-answered="email,mobile">Combining rules
Separate rule names with spaces. They run left to right and the first failure is reported.
<input name="email" data-validation="required email">
<input name="pw" type="password"
data-validation="required strength breached"
data-validation-strength="3">Writing your own
Anything you can express as a function can become a rule. See custom validators in the API reference.
$.formUtils.addValidator({
name: 'even',
validatorFunction: function (value) {
return parseInt(value, 10) % 2 === 0;
},
errorMessage: 'Please give an even number',
errorMessageKey: 'badEvenNumber'
});