validate regex php code example
Example 1: validate names regex php
preg_match("/^([a-zA-Z' ]+)$/","Given_Name");
Example 2: php regex
preg_match('/(foo)(bar)(baz)/', 'foobarbaz', $matches, PREG_OFFSET_CAPTURE);
Example 3: php preg_match
preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) : int
Example 4: regex validation of name in php
case 3:
$rgx = "/^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i";
break;
case 2:
$rgx = "/[^A-Za-z0-9]+/";
break;
case 1:
$rgx = "/[^A-Za-z0-9]+/";
break;
case 0:
$rgx = "/[^A-Za-z0-9]+/";
break;
default:
echo "???";
die("$unit ?");
break;
}
$n = preg_match($rgx, $unit, $matches);
if ( ($idx == 0) || ($idx == 1) || ($idx == 2) ){
if ($n) {
echo "Bad Characters in $unit; Alphanumeric only";
}
} else {
if ($n == 0) {
echo "Incorrect Format in $unit; Enter Valid Info";
}
}