Hello I need help with validation using regular expressions in javascript
I need something like this.
The first character should be a designated character like A, B or C only. and the next 3 characters should be numbers.
example: A123, B345, C234.
D123 is not allowed.
This works for me:
Breakdown:
^matches the beginning of a string(?:A|B|C)matches A or B or C but does not capture it\d{3}matches 3 digits in a row$matches the end of the stringTherefore
'A12'would not be valid because there aren’t 3 digits, nor would' A123'because of leading whitespace, nor would'A123 hello'because the match isn’t at the beginning and end of string.To make it case insensitive, add
iafter the/at the end of the regex.