Some Important regex validation rules.

Some are best for Nepal

Here are some of the list of regex expressions

Note: All the test cases listed below are correct

✔ means the validation passes because the input is correct, &

❌ means the validation fails because the provided input is incorrect.

1. Nepali Citizenship Card Number

\b\d{2}[-\.\ ]?\d{2}[-\.\ ]?\d{2}[-\.\ ]?\d{5}\b

Some Test Cases:

  1. 31-01-76-03422 ✔
  2. 31 01 76 03422 ✔
  3. 31.01.76.03422 ✔
  4. 31017603422 ✔
  5. 258-468-51-2564 ❌
  6. 25-65-899-85-45876 ❌
  7. 954-965-789-125 ❌

2. Visa & MasterCard

\b((4\d{3}|5[1-5]\d{2}|2\d{3}|3[47]\d{1,2})[\s\-]?\d{4,6}[\s\-]?\d{4,6}?([\s\-]\d{3,4})?(\d{3})?)\b

Some Test Cases:

Visa

  1. 4532613257548007 ✔
  2. 4716563756075937 ✔
  3. 4929038415234561233 ✔
  4. 4718 4123 4142 4124 ✔
  5. 4716-5637-5607-5937 ✔

MasterCard

  1. 2720-9928-3988-7281✔
  2. 2720992839887281✔
  3. 5461718001676921✔
  4. 5489790994470834 ✔
  5. 5489 7909 9447 0834 ✔
  6. 5489-7909-9447-0834 ✔

American Express

  1. 372714876128394 ✔
  2. 346781676352683 ✔
  3. 376506566639896 ✔
  4. 3765 065666 39896 ✔
  5. 3467 816763 52683 ✔
  6. 3400 0000 0000 009 ✔

3. Swift Code

A SWIFT Code is a standard format of Bank Identifier Code (BIC) used to specify a particular bank or branch. These codes are used when transferring money between banks, particularly for international wire transfers. Banks also use these codes for exchanging messages between them.

SWIFT codes comprise of 8 or 11 characters. All 11 digit codes refer to specific branches, while 8 digit codes (or those ending in 'XXX') refer to the head or primary office. SWIFT codes are formatted as follows:

AAAA BB CC DDD

First 4 characters - bank code (only letters)

Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)

Next 2 characters - location code, passive participant will have "1" in the second character (letters and digits)

Last 3 characters - branch code, optional - 'XXX' for primary office (letters and digits)

\b[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?\b

Some Test Cases:

  1. ADBLNPKA ✔
  2. BOKLNPKA ✔
  3. CCBNNPKA ✔
  4. CTZNNPKA ✔
  5. NBOCNPKANRD ✔
  6. NRBLNPKAFED ✔
  7. NSBINPKA001 ✔
  8. SNMANPKA ✔