Reputation: 4332
I need a javascript REGEX to check that the length of the string is 9 characters. Starts with 'A' or 'a' and is followed by 8 digits.
Axxxxxxxx
or axxxxxxxx
Upvotes: 4
Views: 278
Reputation:
This is probably what you want.
/^([aA]\d{8})$/
The carot character means the regex must start searching from the beginning of the string, and the dollar character means the regex must finish searching at the end of the string. When they are used together it means the string must be searched from start to end.
The square brackets are used to specific a character or a range of allow characters. The slash and d means to search any digit character. The brackets at the end specify a static quantity that applies to the previous test definition. A range of quantities can be used by specifing a minimum value immediately followed by a comma immediately followed by a maximum value.
Upvotes: 2
Reputation: 33406
/^[aA][0-9]{8}$/
or /^[aA]\d{8}$/
Also makes sure the x
's are digits :)
Upvotes: 12
Reputation: 14959
did you mean this?
/^[aA]\d{8}/
or did you mean 9 chars ?
/^[aA]\d{8}/
or did you mean A + 8 equal chars ?
/[aA](.)\1{7}/
Upvotes: 0