Triandh Velchuri Triandh Velchuri - 1 year ago 80
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download