Category Archives: Regex

Common Csharp dotnet Regex expressions for user input validation

Name Pattern Example US zip code regex ^d{5}(?:[-s]d{4})?$ 12345 or 12345-2345 Canadian zip code regex ^([ABCEGHJKLMNPRSTVXY]d[ABCEGHJKLMNPRSTVWXYZ]) {0,1}(d[ABCEGHJKLMNPRSTVWXYZ]d)$ M4B 1B4 US phone number regex (?d{3})?-? *d{3}-? *-?d{4} (123) 345-234 US Date (MM/dd/YYYY) regex ^(0?[1-9]|[12][0-9]|3[01])[/](0?[1-9]|1[012])[/]d{4}$ 05/31/2016 24 Hour time regex ^(?:0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$ 13:12 12 Hour time regex (AM/PM) ^(([0]?[0-9]|1[0-2]):[0-5][0-9][ ][aApP][mM])|((1[3-9]|2[0-3]):[0-5][0-9])$ 7:00 AM Url regex ^(https?://)?([da-z.-]+).([a-z.]{2,6})([/w .-]*)*/?$ http://www.test.com or… Read More »