The code is as follows:
<script type= "Text/javascript" >
function Checkurl () {
var url = document.getElementById (' URL '). value;
if (url== ') {
alert (' URL address cannot be empty ');
return false;
} else if (!isurl (URL)) {
alert (' URL should be in the format of Http://www.jb51.net ');
return false;
} else {
return true;
}
return false;
}
function Isurl (str)
{
varreg=/[0-9a-za-z]+. (html|htm|shtml|jsp|asp|php|com|cn|net|com.cn|org) $/;
Must contain. (The last one is at least one character ahead) and. There is at least one word character at the back, the final character must be a word character or/
varreg=/w+. (w+|w+/) $/;
Varisurl=reg.test (str);//test (str) method is a JS correct expression built-in object can be directly called
Returnisurl;
}
</script>
The
code is as follows:
<form action= "method=" post "onsubmit=" Checkurl (); " >
Url:
<input type= "text" name= "url" id= "url" value= "http://www.jb51.net" onfocus= "this.value=" "/>
<br/><br/>
<input type= "Submit" value= "Fetch address" name= "get"/>
<input type= "Submit" value= "Download" name= "Download"/>
</form>
PHP detects URL address validity
The code is as follows
The
code is as follows:
;?
function Is_url ($str) {
return Preg_match ("/^http://[a-za-z0-9]+.[ a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> "]) *$/", $str);
}
?>
If you want to try the normal method we can use the file_get_contents () function to verify it.