2

I'm new to regular expressions and can't get the hang of them. Can you provide me with some help?

I need a regular expression to assign to a textbox that will allow 6 numbers followed by an A,M or G.

The following is the furthest I've got, it allows 6 numbers but that's it:

 ^[0-9]{6}

1 Answer 1

8

You were close.

^[0-9]{6}[AMG]$

^: Start of string
[0-9]{6}: match 6 numbers between 0-9, inclusive
[AMG]: match 1 of the letters
$: end of string

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! it worked perfectly. Will set your answer to accepted answer once the 10 mins past by. What would i have to type if i wanted "AMG" as a whole string as the ending?
You would use either ^[0-9]{6}AMG$ or ^[0-9]{6}[A][M][G]$ I believe the first one would work, but you're guaranteed the second one does.
first one ^[0-9]{6}AMG$ should be fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.