| Name | HTML attribute | Type | Description |
|---|---|---|---|
message
|
data-fv-credit-card___message
|
String
|
The error message |
| Type | Sample |
|---|---|
| American Express | 340653705597107 |
| Dankort | 5019717010103742 |
| Diners Club | 30130708434187 |
| Diners Club (US) | 5517479515603901 |
| Discover | 6011734674929094 |
| Elo | 6362970000457013 |
| JCB | 3566002020360505 |
| Laser | |
| Maestro | 6762835098779303 |
| Mastercard | 5303765013600904 |
| Solo | 6334580500000000 |
| Visa | 4929248980295542 |
| Visa Electron | 4917300800000000 |
// You might need to change the importing path
import
creditCard
from
'formvalidation/dist/es6/validators/creditCard'
;
const
result
=
creditCard
(
)
.
validate
(
{
value
:
...
,
options
:
{
message
:
...
,
}
,
}
)
;
/*
result is an object of
{
valid: true or false,
message: The error message,
meta: {
// The type of credit card
// Can be null or one of AMERICAN_EXPRESS, DINERS_CLUB, DINERS_CLUB_US, DISCOVER, JCB, LASER,
// MAESTRO, MASTERCARD, SOLO, UNIONPAY, VISA
type: ...
}
}
*/
// You might need to change the importing path
import
creditCard
from
'formvalidation/dist/es6/validators/creditCard'
;
const
res1
=
creditCard
(
)
.
validate
(
{
value
:
'340653705597107'
,
options
:
{
message
:
'The credit card number is not valid'
,
}
,
}
)
;
// res1.valid === true
// res1.meta.type === 'AMERICAN_EXPRESS'
const
res2
=
creditCard
(
)
.
validate
(
{
value
:
'5303765013600'
,
options
:
{
message
:
'The credit card number is not valid'
,
}
,
}
)
;
// res2.valid === false
// res2.meta.type === null