Triandh Velchuri Triandh Velchuri - 2 months ago 5
ASP.NET (C#) Question

Multiple expressions in one Regular expression

I had written the below regular expression

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

This will allow the numbers like "AA1234567".

I want to write the regular expression to allow below formats "AA1234567-12345" or "AA1234567" in one expression.

Can anyone please help me how can i write that

sln sln
Answer

You can try "^[a-zA-Z]{2}[0-9]{7}(?:-[0-9]{5})?$

Comments