regex

IP Address Validation

An IP address is one of an IPv4 address, an IPv6 address, or an IPv4-mapped IPv6 address.

An IPv4 address consists of four groups, separated by dots, each containing a decimal value between 0 and 255. A regular expression check to match for an IPv4 address would be as follows:

// IPv4 address

'/^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?1)){3}$/D'

Read More

Tags: ,

Monday, August 16th, 2010 PHP 1 Comment

Email Address Validation

Email addresses have a local-part and a domain separated by an (unquoted) “@” symbol. The local-part must be either a dot-atom or a quoted string, and the domain must be either a domain name or a domain literal.

A dot-atom can only contain letters, numbers, dots, and the following characters: ! # $ % & ‘ * + – / = ? ^ _ ` { | } ~. However, neither the first nor the last character can be a dot, and two or more consecutive dots are not allowed. The maximum length of a dot-atom is 64 characters. A regular expression to match for a dot-atom local-part would be as follows:

// Dot-atom

/^(?!.{65,})([!#-'*+\/-9=?^-~-]+)(?>\.(?1))*$/iD

Read More

Tags: ,

Sunday, December 20th, 2009 PHP 18 Comments