0

I need to validate a specific format of numbers and letters,

What would be the regex string that would check

nnnnnnnnnA (example 123456789A)

I tried

^[0-9]^[0-9]^[0-9]^[0-9]^[0-9]^[0-9]^[0-9]^[0-9]^[0-9]{A-Z}$

but it's not forcing the 9 number plus one letter

2
  • Which part or parts of that example is variable? Commented Oct 2, 2013 at 21:09
  • Please, as the regex tag tooltip explains, provide a specific language or tool that you are using. Regex is not standardized across all languages. Commented Oct 2, 2013 at 21:45

2 Answers 2

2

Typically, with regex, you can look for a set number of things in the following way:

\d{1,10} 

In this case, it's looking for between 1 and 10 total digits.

You can also use a ^ to search for something at the beginning of a line, but it doesn't really make sense in your context look for "beginning-of-line then 0-9, beginning of line, then 0-9", etc. This is what your regex seems to be attempting to match and this is most likely the reason it doesn't produce anything.

Thus, your regex will probably need to look for something like this:

\d{9}[A-Za-z]

This means a string with 9 digits and a letter at the end (lowercase and uppercase depending on the implementation. In some cases you can do [A-z] while if you just wanted uppercase, you can do [A-Z]).

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

Comments

1

It depends on your regular expression engine.

The most basic would be:

^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]$

but the following should work with most engine:

^\d{9}[A-Z]$

Comments

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.