Skip to content

Month: September 2013

Regex for Credit Card Numbers

Here is a regular expression for credit card numbers.

string ccRegEx = @"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$";

Regex for U.S. and Canadian Zip Codes

Below is the regex code for U.S. and Canadian zip codes. I’m don’t remember where I found these but hopefully someone finds them useful.

string _usZipRegEx = @"^\d{5}(?:[-\s]\d{4})?$";