Javascript使用正则表达式检测用户输入的URL地址是否有效:
<html><head><title>检查是否为URL</title><script language="javascript"> function check(){ str = form1.txt.value; //str = str.match(/http:\/\/.+/); str = str.match(/^http:\/\/.+\..+/i); if (str == null){ alert('你输入的URL无效'); return false; }else{ alert("你输入的URL有效"); return true; } }</SCRIPT></head><body><form name="form1" onSubmit="return check()"> <input type="text" name="txt"> <input type="submit" value="检验"></form></body></html>