12-05-2007, 12:08 AM
|
#6 (permalink)
|
|
The Contributor
Join Date: Oct 2007
Location: Argentina
Posts: 72
Thanks: 18
|
Revised Regular expressions:
TELEPHONE
PHP Code:
$string = "(232) 555-5555";
if (preg_match('/^\(?[0-9]{3}\)?|[0-9]{3}[-. ]? [0-9]{3}[-. ]?[0-9]{4}$/', $string)) {
echo "example 2 successful.";
}
EMAIL
PHP Code:
$string = "first.last@domain.co.uk";
if (preg_match(
'/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/',
$string)) {
echo "example 3 successful.";
POSTAL CODE
PHP Code:
$string = "55324-4324";
if (preg_match('/^[0-9]{5}([- ]?[0-9]{4})?$/', $string)) {
echo "example 4 successful.";
}
IP ADDRESS
PHP Code:
$string = "255.255.255.0";
if (preg_match(
'/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/',
$string)) {
echo "example 5 successful.";
}
HEXADECIMAL COLORS
PHP Code:
<?php
$string = "#666666";
if (preg_match('/^#(?:(?:[a-f0-9]{3}){1,2})$/i', $string)) {
echo "example 6 successful.";
}
?>
MULTI-LINE COMMENTS
PHP Code:
<?php $string = "/* commmmment */";
if (preg_match('#/\*.*?\*/#ms', $string)) {
echo "example 7 successful.";
} ?>
Thanks guys for the feedback  , i followed your suggestions and made the necessary arrangements, let me know if these are ok or if you have anything else to share/add to these
Thanks again!
|
|
|
|