| Name | HTML attribute | Type | Description |
|---|---|---|---|
flags
|
data-fv-regexp___flags
|
String
|
If specified, flags can have any combination of JavaScript regular expression flags such as
g
(global match),
i
(ignore case),
m
(multiple line)
|
message
|
data-fv-regexp___message
|
String
|
The error message |
regexp
*
|
data-fv-regexp___regexp
or
pattern
|
String
or
RegExp
|
The JavaScript regular expression |
// You might need to change the importing path
import
regexp
from
'formvalidation/dist/es6/validators/regexp'
;
const
result
=
regexp
(
)
.
validate
(
{
value
:
...
,
options
:
{
flags
:
...
,
message
:
...
,
regexp
:
...
,
}
,
}
)
;
/*
result is an object of
{
valid: true or false,
message: The error message
}
*/
^
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.
^
(
?
!
000
|
666
)
(
?
:
[
0
-
6
]
[
0
-
9
]
{
2
}
|
7
(
?
:
[
0
-
6
]
[
0
-
9
]
|
7
[
0
-
2
]
)
)
-
(
?
!
00
)
[
0
-
9
]
{
2
}
-
(
?
!
0000
)
[
0
-
9
]
{
4
}
$
// without seconds (hh:mm)
^
(
1
[
0
-
2
]
|
0
?
[
1
-
9
]
)
:
(
[
0
-
5
]
?
[
0
-
9
]
)
$
// with seconds (hh:mm:ss)
^
(
1
[
0
-
2
]
|
0
?
[
1
-
9
]
)
:
(
[
0
-
5
]
?
[
0
-
9
]
)
:
(
[
0
-
5
]
?
[
0
-
9
]
)
$
// without seconds (hh:mm)
^
(
2
[
0
-
3
]
|
[
01
]
?
[
0
-
9
]
)
:
(
[
0
-
5
]
?
[
0
-
9
]
)
$
// with seconds (hh:mm:ss)
^
(
2
[
0
-
3
]
|
[
01
]
?
[
0
-
9
]
)
:
(
[
0
-
5
]
?
[
0
-
9
]
)
:
(
[
0
-
5
]
?
[
0
-
9
]
)
$
// Range of 1-12 (hour, month)
^
(
1
[
0
-
2
]
|
[
1
-
9
]
)
$
// Range of 1-24 (hour)
^
(
2
[
0
-
4
]
|
1
[
0
-
9
]
|
[
1
-
9
]
)
$
// Range of 0-59 (minute, second)
^
[
1
-
5
]
?
[
0
-
9
]
$
// Range of 1-31 (day of month)
^
(
3
[
01
]
|
[
12
]
[
0
-
9
]
|
[
1
-
9
]
)
$
// Range of 0-100 (percentage)
^
(
100
|
[
1
-
9
]
?
[
0
-
9
]
)
$
pattern
attribute.
// You might need to change the importing path
import
regexp
from
'formvalidation/dist/es6/validators/regexp'
;
const
res1
=
regexp
(
)
.
validate
(
{
value
:
'Ms'
,
options
:
{
regexp
:
/
^[A-Z\s]+$
/
,
message
:
'The input is not valid'
,
}
,
}
)
;
// res1.valid === false
const
res2
=
regexp
(
)
.
validate
(
{
value
:
'form VALIDATION'
,
options
:
{
regexp
:
'^[A-Z\\s]+$'
,
flags
:
'i'
,
message
:
'The input is not valid'
,
}
,
}
)
;
// res2.valid === true