Archive for October, 2012

Essential Regex

October 3, 2012 Leave a comment

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 #

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}
%d bloggers like this: