Reputation: 31
Is this the correct regular?
^[ASB]{3}[0-9]{6,}$
I want to validate the number (using JavaScript) which should have three prefixed letters ASB followed by 6 digits e.g. ASB673567
Upvotes: 0
Views: 54
Reputation: 174706
You need to remove the first character class,. [ASB]
matches any one of the character from the given list, that is here it may match A
or S
or B
. So by repeating the character class exactly three times, [ASB]{3}
not only matches ASB
but also AAA
or AAB
or .......
^ASB[0-9]{6,}$
This would match 6 or more digits prefixed with ASB
For exactly 6 digits.
^ASB[0-9]{6}$
Upvotes: 1