4

I need to validate a string of number for non repeating numbers and a count match in JavaScript using regex

Use case :

  1. The string should have only numbers.
  2. The string should only be of length 9
  3. The string should not have two same numbers

Example :

123456789 should be valid

123456788 should be invalid - Same number not allowed twice

12345678 should be invalid - Doesn't have 9 numbers

1234567890 should be invalid - Has more than 9 numbers

I used below code to find a count match but don't know how to check for non repeating numbers

/(^\d{9}$)/

0 Answers0