// checks postal code format L4X-1S9
$regex = '/[a-z][0-9][a-z][- ]?[0-9][a-z][0-9]$/i';
if( preg_match($regex, $zip) )
echo "Valid postal code";
// checks for 5 digit or 9 digit zip code or 12345-6789
// or 123456789
$regex = '/(^\d{5}$)|(^\d{5}-\d{4}$)|(^\d{9}$)/'
if( preg_match($regex, $zip) )
echo "Valid Zip code";
Showing posts with label Regex. Show all posts
Showing posts with label Regex. Show all posts
// to validate rgb input
static function is_valid_rgb($rgb_values) {
// format expected is: array(255,125,60)
if(!is_array($rgb_values) || count($rgb_values) != 3)
return false;
foreach($rgb_values as $rgb_value) {
if(!preg_match('/^[0-9]{1}$|^[0-9]{2}$|^[0-1]{1}[0-9]{1}[0-9]{1}$|^[2]{1}[0-5]{1}[0-5]{1} $/',$rgb_value))
return false;
}
return true;
} // end of function
// to validate cymk input
static function is_valid_cymk($cymk_values) {
// format expected is: array(255,125,60,199)
if(!is_array($cymk_values) || count($cymk_values) != 4)
return false;
foreach($cymk_values as $cymk_value) {
if(!preg_match('/^[0-9]{1}$|^[0-9]{2}$|^[0-1]{1}[0-9]{1}[0-9]{1}$|^[2]{1}[0-5]{1}[0-5]{1}$/',$cymk_value))
return false;
}
return true;
}
Subscribe to:
Posts (Atom)