<title> Check for url</title>
<script language= "Web Effects" >
function Check () {
str = Form1.txt.value;
str = Str.match (/http://.+/);
if (str = null) {
Alert (' The URL you entered is invalid ');
return false;
}else{
Alert ("The URL you entered is valid");
return true;
}
}
</script>
<body>
<form name= "Form1" onsubmit= "return Check ()" >
<input type= "text" name= "TXT" >
<input type= "Submit" value= "Inspection" >
</form>
</body>
Instance validation code two
The main validation is the regular expression of the format. This is a common method, of course, can be more intelligent to write logical code, or to increase the B/s protocol
function Isurl (str_url) {//Authentication URL
var Strregex = "^ (https tutorial |http|ftp|rtsp|mms)?:/ /)"
+ "? ([0-9a-z_!~* ' (). &=+$%-]+:)? [0-9a-z_!~* ' (). &=+$%-]+@)? " user@ of FTP
+ "([0-9]{1,3}.) {3} [0-9] {1,3} "//IP form of url-199.194.52.184
+ "|"//Allow IP and domain (domains)
+ "([0-9a-z_!~* ' ()-]+.) * "//Domain name-www."
+ "([0-9a-z][0-9a-z-]{0,61})?" [0-9a-z]. " Level two domain name
+ "[a-z]{2,6}]"///domain-. com or. Museum
+ "(: [0-9]{1,4})?"//Port-: 80
+ "((/?)|" A slash isn ' t required if there is no file name
+ "(/[0-9a-z_!~* ' ().;?: @&=+$,%#-]+) +/?" $";
var re = new RegExp (Strregex);
Return Re.test (Str_url);
}
A more advanced URL-Address validation function
It verifies that the situation includes: IP, domain, FTP
Two-level domain name, the domain name of the file, domain name plus port.
<script language= "JavaScript" >
<!--
function Isurl (str_url) {
var Strregex = "^ (HTTPS|HTTP|FTP|RTSP|MMS)?:/ /)"
+ "? ([0-9a-z_!~* ' (). &=+$%-]+:)? [0-9a-z_!~* ' (). &=+$%-]+@)? " user@ of FTP
+ "([0-9]{1,3}.) {3} [0-9] {1,3} "//IP form of url-199.194.52.184
+ "|"//Allow IP and domain (domains)
+ "([0-9a-z_!~* ' ()-]+.) * "//Domain name-www."
+ "([0-9a-z][0-9a-z-]{0,61})?" [0-9a-z]. " Level two domain name
+ "[a-z]{2,6}]"///domain-. com or. Museum
+ "(: [0-9]{1,4})?"//Port-: 80
+ "((/?)|" A slash isn ' t required if there is no file name
+ "(/[0-9a-z_!~* ' ().;?: @&=+$,%#-]+) +/?" $";
var re=new regexp (Strregex);
Re.test ()
if (Re.test (Str_url)) {
return (true);
}else{
return (false);
}
}
-->
</script>