-1

What is a suitable regular expression to validate that a string matches the format A123456

First letter must be a letter upper case or lower case then exactly 6 numeric numbers following it.

I'm using c# .net if that has any effect on the formatting.

Jammy
  • 779
  • 2
  • 13
  • 26
  • 2
    Have you tried something? It's really basic. – Toto Mar 03 '15 at 13:19
  • Needed the answer in a rush and i was getting confused reading examples and figured the kind people here would help clarify for me. Thanks for the help. – Jammy Mar 03 '15 at 13:42

3 Answers3

2

Well, you need to search for the following pattern:

  • ((?i)) - [Modifiers] Case-insensitive
  • (^) - Begin
    • ([a-z]) - A single letter
    • (\d{6}) - Digits 0-9 with length of 6
  • ( $) - End

Resulting regular expression: (?i)^[a-z]\d{6}$

Regex alpha1numeric6Pattern = new Regex(@"(?i)^[a-z]\d{6}$");

See it in action: 3aaeea6ad8ce3e4ab9ac@csharppad.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
1

Try this:

^[a-zA-Z]\d{6}$

You would benefit from a quick read at http://www.regularexpressions.info

Bohemian
  • 412,405
  • 93
  • 575
  • 722
1

This would do what you are after: ^[A-Za-z]\d{6}$. An example can be seen here.

npinti
  • 51,780
  • 5
  • 72
  • 96