Wednesday, 16 November 2011

REGEXP: Validate IP

The validation of the IP it's very simple, you need a Regular expression and put it into the function preg_match, this is an example:

function checkIP($ip) {
    return preg_match("/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/i", $ip);
}