| Name | HTML attribute | Type | Description |
|---|---|---|---|
format
*
|
data-fv-date___format
|
String
|
The date format. It is
MM/DD/YYYY
, by default
|
max
|
data-fv-date___max
|
String
or
Date
or
Function
|
The value must be earlier than this option |
message
|
data-fv-date___message
|
String
|
The error message |
min
|
data-fv-date___min
|
String
or
Date
or
Function
|
The value must be later than this option |
separator
|
data-fv-date___separator
|
String
|
Used to separate the day, month, and year |
separator
option isn't defined, the validator will look for the following separators automatically:
min
and
max
options can be
format
option
Date
object
format
can combine date, time, and AM/PM indicator sections:
| Section | Token | Separator |
|---|---|---|
| Date | DD, MM, YYYY |
Defined by the
separator
option. Most popular examples are a slash (/), hyphen (-), or dot (.)
|
| Time | h, m, s | a colon (:) |
| AM/PM | A | n/a |
| Token | Description | Required |
|---|---|---|
| MM | Month number | Yes |
| DD | Day of month | Yes |
| YYYY | 4 digit year | Yes |
| h | 12 hour time | No |
| m | Minutes | No |
| s | Seconds | No |
| A | AM/PM | No |
HH:mm
, for example, you should use the
regexp validator
.
// You might need to change the importing path
import
date
from
'formvalidation/dist/es6/validators/date'
;
const
result
=
date
(
)
.
validate
(
{
value
:
...
,
options
:
{
format
:
...
,
max
:
...
,
message
:
...
,
min
:
...
,
separator
:
...
,
}
,
}
)
;
/*
result is an object of
{
valid: true or false,
message: The error message,
meta: {
// Can be null (if the value is not a valid date)
// or a JavaScript Date object presenting the value
date: ...,
}
}
*/
// You might need to change the importing path
import
date
from
'formvalidation/dist/es6/validators/date'
;
const
res1
=
date
(
)
.
validate
(
{
value
:
'2014/08/17'
,
options
:
{
format
:
'YYYY/MM/DD'
,
message
:
'The value is not a valid date'
,
min
:
'2010/01/01'
,
}
,
}
)
;
// res1.valid === true
// res1.meta.date === new Date('2014/08/17')
const
res2
=
date
(
)
.
validate
(
{
value
:
''
,
options
:
{
format
:
'DD.MM.YYYY'
,
message
:
'The value is not a valid date'
,
}
,
}
)
;
// res2.valid === false
// res2.meta.date === null
min
,
max
options accept a function returning a
Date
object or a string
separator
option isn't determined properly