JavaScript verifies that the user entered the correct URL address

Source: Internet
Author: User

<script type= "Text/javascript" >
function Checkurl () {
var url = document.getElementById (' URL '). value;
if (url== ') {
Alert (' URL address cannot be null ');
return false;
} else if (!isurl (URL)) {
Alert (' URL format should be http://www.111cn.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 be included. (The last one. There is at least one character in front) and. There is at least one word character behind it, and the final character must be a word character or/
varreg=/w+. (w+|w+/) $/;
Varisurl=reg.test (str);//test (str) method is JS the correct expression built-in object can be called directly (www.111cn.net)
Returnisurl;
}
</script>


<form action= "" method= "Post" onsubmit= "Checkurl ();" >
Url:
<input type= "text" name= "url" id= "url" value= "http://www.111cn.net" onfocus= "this.value=" "/>
<br/><br/>
<input type= "Submit" value= "Get Address" name= "get"/>
<input type= "Submit" value= "Download" name= "Download"/>
</form>

PHP detects URL address validity

Code to copy code as follows
<?
function Is_url ($STR) {
Return Preg_match ("/^http://[a-za-z0-9]+.[ a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> "]) *$/", $str);
}
?>

We can use the file_get_contents () function to verify if we want to try a normal method.
From:http://www.111cn.net/wy/js-ajax/50084.htm

JavaScript verifies that the user entered the correct URL address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.