每个有效 URL 的正则表达式
<?php
function validateURL($val) {
$pattern_1 = "/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i";
$pattern_2 = "/^(www)((\.[A-Z0-9][A-Z0-9_-]*)+.(in|com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i";
$pattern_3 = "/^(([A-Z0-9][a-zA-Z0-9_-]*)+.(co|in|com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i";
$pattern_4 = "/^(([A-Z0-9][a-zA-Z0-9_-]*)+.(co|in|com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se*)+.(co|in|com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i";
if(preg_match($pattern_1, $val) || preg_match($pattern_2, $val) || preg_match($pattern_3, $val) || preg_match($pattern_4, $val)){
return true;
} else{
return false;
}
}
$url = "google.com.in";
echo validateURL($url);
?>