Triandh Velchuri Triandh Velchuri - 7 months ago 39
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

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