Skip to content

Add modulo10 rule #63

Description

@zrvan

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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions