Monthly Archives: January 2011

A regex that matches all credit cards

Regular Expression For Credit Card Numbers

Regular Expression For Credit Cards

This is a regular expression that validates all credit card numbers including VISA, MASTER, AMEX and DISCOVERY! ^((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$

<asp:RegularExpressionValidator ID="CreditCardValidator" runat="server" 
   ControlToValidate="CreditCardNumber" Display="Static" 
   ErrorMessage="Please enter valid card number" 
   ValidationExpression="^((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$"  
  ValidationGroup="CustomSignup" Text="*" />