Reputation: 289
How can I format this so it only checks if my string starts with the letter "a" or "b" and also accepts misc. characters after this (numbers or letters)?
Just need to make sure it starts with the letter a or b, the rest is ok and will have more characters.
mystring.match(/^D\d{22}$/i
Upvotes: 1
Views: 113
Reputation: 816532
If you only want to match whether the string starts with a
or b
, it would be a completely different expression:
/^[ab][a-z\d]*/i.test(mystring)
Edit: Updated to much arbitrary characters afterwards.
Edit2: Restricted to numbers and letters.
Of course you can also combine this with any other expression if you want to.
This is great source to learn about regular expressions.
Upvotes: 1
Reputation: 531
This should work "/^[ab][A-Za-z0-9_-]*$" for generic string to start with "a" or "b" use link to verify RegEx online.
Upvotes: 1
Reputation: 206727
"Start with a or b" would be in regex-speech:
/^[ab]
then you put the rest of your pattern match.
Upvotes: 1