Home > C# > Essential Regex

Essential Regex

By this time you all know how “regex” (Regular Expressions) have proved to be beneficial when it comes to either validations or comparisons; and yes that was actually an intent of this post to include some of the frequently used regex used by programmers.

American Express card #
3[47][0-9]{13}|3[47]\d{2}[ -]*\d{6}[ -]*\d{5}|[ -]*3[ -]*[47][ -]*(?:\d[ -]*){13}

Diners Club card #
3(?:0[0-5]|[68][0-9])\d[ -]*\d{6}[ -]*\d{4}|[ -]*3[ -]*(?:0[ -]*[0-5]|[68][ -]*[0-9])[ -]*(?:\d[ -]*){11}

Discover card #
6(?:011|5[0-9]{2})[0-9]{12}

Master Card card #
5[1-5][0-9]{14}|5[1-5]\d{2}[ -]*\d{4}[ -]*\d{4}[ -]*\d{4}|[ -]*5[ -]*[1-5][ -]*(?:[0-9][ -]*){14}

Visa card #
4[0-9]{12}(?:[0-9]{3})?|4\d{3}[ -]*\d{4}[ -]*\d{4}[ -]*\d(?:\d{3})?|[ -]*4[ -]*(?:\d[ -]*){12}(?:(?:\d[ -]*){3})?

UK National Insurance numbers
[abceghj-prstw-z][abceghj-nprstw-z] ?\d{2} ?\d{2} ?\d{2} ?[a-dfm]?

US social security numbers
(?!000)(?!666)(?:[0-6]\d{2}|7(?:[0-356]\d|7[012]))[- ](?!00)\d{2}[- ](?!0000)\d{4}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: