It would be useful to have a validation rule for modulo 10 (and quite likely other check-digit verification algorithms, though this issue is limited to modulo 10).
My specific use case would be for validation of Swedish national identification numbers, which are (for validation purposes) two part, the first specifying the century of birth and the second part specifying the date of birth, some additional digits and a mod10/luhn check digit. It might look something like this:
{
"swedish_national_identification_number": {
"nested_object": {
"century": [
"required",
{
"number_between": [
19,
20
]
}
],
"number": [
"required",
"modulo10"
]
}
}
}
Another case that comes to mind is the credit card validation in js-livr-extra-rules. It could perhaps be expressed along the lines of an alias like:
{
"name": "credit_card",
"rules": [
"string",
{
"length_between": [
14,
16
]
},
"modulo10"
],
"error": "WRONG_CREDIT_CARD_NUMBER"
}
This would not be strictly equivalent, but with the addition of the experimental
it would be functionally equivalent to the js-livr-extra-rules's code, but using only core rules.
As noted earlier modulo10 is only one among a number of check-digit verification algorithms, so it might make sense to use a prefix to signal that it belongs to a family of rules.
It would be useful to have a validation rule for
modulo 10(and quite likely other check-digit verification algorithms, though this issue is limited to modulo 10).My specific use case would be for validation of Swedish national identification numbers, which are (for validation purposes) two part, the first specifying the century of birth and the second part specifying the date of birth, some additional digits and a mod10/luhn check digit. It might look something like this:
{ "swedish_national_identification_number": { "nested_object": { "century": [ "required", { "number_between": [ 19, 20 ] } ], "number": [ "required", "modulo10" ] } } }Another case that comes to mind is the credit card validation in
js-livr-extra-rules. It could perhaps be expressed along the lines of an alias like:{ "name": "credit_card", "rules": [ "string", { "length_between": [ 14, 16 ] }, "modulo10" ], "error": "WRONG_CREDIT_CARD_NUMBER" }This would not be strictly equivalent, but with the addition of the experimental
{ "like": "^\\d*$" }it would be functionally equivalent to the
js-livr-extra-rules's code, but using only core rules.As noted earlier
modulo10is only one among a number of check-digit verification algorithms, so it might make sense to use a prefix to signal that it belongs to a family of rules.