Triandh Velchuri Triandh Velchuri - 1 month ago 15
C# Question

Regular expression value update

I had written the below regular expression

string validnumber = @"^[a-zA-Z]{2}[0-9]{7}(?:-[0-9]{5})?$";


This will allow the numbers like "AA1234567" and "AA1234567-12345".

I want to allow below all formats

AA1234567?
AA1234567??
AA1234567???
AA1234567????

AA1234567-?
AA1234567-??
AA1234567-???
AA1234567-????


Can anyone please help me how can i write that

Answer

Try this:

^[a-zA-Z]{2}\d{7}(?:-?\d{1,4})?$

Explanation

Updated as per the comments

Comments