The code copy 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 //www.VeVB.COM');
return false;
} else {
return true;
}
return false;
}
function isURL(str)
{
//varreg=/[0-9a-zA-z]+.(html|html|html|shtml|jsp|asp|php|com|cn|net|com.cn|org)$/;
// Must contain. (The last one. At least one character is preceded) and. At least one word character is followed by, and the last character must be a word character or/
varreg=/w+.(w+|w+/)$/;
varisurl=reg.test(str);//test(str) method is that the built-in object of the correct expression of js can be called directly
returnisurl;
}
</script>
The code copy is as follows:
<form action="" method="post" onsubmit="checkUrl();">
URL:
<input type="text" name="url" id="url" value="//www.VeVB.COM" onfocus="this.value=''"/>
<br /><br />
<input type="submit" value="get address" name="get"/>
<input type="submit" value="Download" name="download"/>
</form>
PHP detects the validity of URL addresses
The code is as follows
The code copy 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 whether it is a normal method, we can use the file_get_contents() function to verify it.