Options
* — Required option
Option | HTML attribute | Type | Description |
---|---|---|---|
message |
data-fv-regexp-message |
String | The error message |
regexp * |
data-fv-regexp-regexp or pattern |
String | The Javascript regular expression |
You don't need to do that when using HTML 5 pattern="..." attribute.
Using a correct pattern
If the validator still pass when the field value doesn't match the pattern, please ensure you use a correct pattern.
Here are some check lists:
-
Is the pattern wrapped between
^
and$
?For example, if a field must be 5 digits number, then
^\d{5}
(no$
at the end) is wrong pattern.^\d{5}$
is right one. -
Does the pattern work with external services?
You can use the following services to test the regular expression:
Useful patterns
The following table collects some useful patterns:
Description | Pattern |
---|---|
SSN (Social Security Numbers) | ^(?!000|666)(?:[0-6][0-9]{2}|7(?:[0-6][0-9]|7[0-2]))-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$
|
Traditional time in 12-hour format |
|
Traditional time in 24-hour format |
|
Numbers in a particular range |
|
ejemplos
In the following form, user is asked to enter the full name which alphabetical characters and spaces only.
Basic example
HTML 5 example
By default, the regexp validator will be used if the field uses HTML 5
pattern
attribute. In order to disable the validator, just simply set
data-fv-regexp="false"
.
Validating social account URL
Instead of using the uri validator, this example uses the
regexp validator to validate Facebook account URL, such as
http(s)://facebook.com/account
: