用于url验证的java脚本
我只是希望对网站URL检查的验证. 但是它不应从http://开始(例如http://www.yahoo.com) 它应该从WW.(示例www.yahhoo.com) 提前
# 回答1
PLESE固定场
选择 | 换行 | 行号
- if(document.frmRegister.WebSite.value!="")
- {
- if (document.frmRegister.WebSite.value.indexOf ('www', 0) == -1 || document.frmRegister.WebSite.value.length < 10)
- {
- if(document.frmRegister.WebSite.value.indexOf ('.com', 0) == -1 || document.frmRegister.WebSite.value.length < 10)
- {
- alert ("Enter a valid URL")
- document.frmRegister.WebSite.focus();
- return false;
- }
- }
- }
# 回答2
选择 | 换行 | 行号
- if(document.frmRegister.WebSite.value!="")
- {
- if (document.frmRegister.WebSite.value.indexOf ('www', 0) == -1 || document.frmRegister.WebSite.value.length < 10)
- {
- if(document.frmRegister.WebSite.value.indexOf ('.com', 0) == -1 || document.frmRegister.WebSite.value.length < 10)
- {
- alert ("Enter a valid URL")
- document.frmRegister.WebSite.focus();
- return false;
- }
- }
- }
# 回答3
嗨,我是这个网站的新事物. 请帮助我,我坚持网站验证BCOZ, 我想以这种方式进行验证, 用户只能在(http://www.test.com)或任何一个(www.test.com)中输入网站. 接受此类型的条目显示警报" PLZ以正确的方式输入网站", 我使用了您的样式,但是当我们在多次中输入点(.) (http://wwwwww.c....test....com)或(wwwwww .......................................................................................................... ... com)
# 回答4
你好, 这可能会帮助您...
选择 | 换行 | 行号
- function isURL ( txtId ){
- var string = document.getElementById(txtId).value;
- if ( string.search(/^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/) != -1 ){
- alert('Valid URL');
- return true;
- }
- if ( string.search(/^[http://]+[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/) != -1 ){
- alert('valid URL');
- return true;
- }
- alert('Not a valid URL');
- document.getElementById(txtId).select();
- document.getElementById(txtId).focus();
- return false;
- }
问候,
# 回答5
不完全的. 那将与一些无效的匹配匹配,并且与很多有效的匹配. 但是,您对使用正则表达式有了正确的想法. 您使用哪一个取决于您希望的准确性. 您可以通过搜索" URL正则表达式"来找到一些好的.
# 回答6
我曾经使用过正则表达式,但没有检查dot,在y y y y y y y y y y y y y y y y y y y y y s y m s y m in s y m in s of veration swork中有多少个点.... 我已经使用了此验证,它检查了http:// www,但我再次坚持下去.
选择 | 换行 | 行号
- if( (website != "") || (website != null) )
- {
- if (website.indexOf ('http://', 0) == -1 )
- {
- if (website.indexOf ('www.', 0) == -1 || website.length < 10)
- {
- if(website.indexOf ('.com', 0) == -1 || website.length < 10)
- {
- alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
- document.filmsForm.url.focus();
- document.filmsForm.url.value = "" ;
- return false;
- }
- }
- var split = website.split("\.");
- if(isNaN(split[0]))
- {
- if( (split[0].length > 3) || (split[0].length < 2) )
- {
- alert("The Length Of www Must Be '3' !");
- document.filmsForm.url.focus();
- document.filmsForm.url.value = "" ;
- return false;
- }
- }else
- {
- alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
- document.filmsForm.url.focus();
- document.filmsForm.url.value = "" ;
- return false;
- }
- } else {
- if (website.indexOf('www.', 0) == -1 || website.length < 10)
- {
- if(website.indexOf('.com', 0) == -1 || website.length < 10)
- {
- alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
- document.filmsForm.url.focus();
- document.filmsForm.url.value = "" ;
- return false;
- }
- }
- var splitfromhttp = website.split("http://");
- var splitfromdot = splitfromhttp[1].split("\.");
- if(isNaN(splitfromdot[0]))
- {
- if( (splitfromdot[0].length > 3) || (splitfromdot[0].length < 2) )
- {
- alert("The Length Of www Must Be '3' !");
- document.filmsForm.url.focus();
- document.filmsForm.url.value = "" ;
- return false;
- }
- }else
- {
- alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
- document.filmsForm.url.focus();
- document.filmsForm.url.value = "" ;
- return false;
- }
- }
- }
- >
# 回答7
与其进行很多检查,不如使用一个正则表达式,例如:
选择 | 换行 | 行号
- /^(http://)?www\.[a-z]+\.com$/gi
一个非常简单的一个只能匹配字母URL,而不匹配具有数字,连字符等的字母URL.它也只能匹配.com,这似乎是您正在检查的.
# 回答8
嘿,我在软件(regesxbilder)上测试此正则表达式,但表明正则表达式是佩戴的.
# 回答9
那是我在没有测试的情况下想到的一个快速示例. 您需要逃脱前锋的斜线:
选择 | 换行 | 行号
- /^(http:\/\/)?www\.[a-z]+\.com$/gi
请注意,这绝不是完整的测试. 为此,您将需要更复杂的东西.
# 回答10
thanx我通过正则表达方式得到了解决方案....是的! 将其(正则表达式)正确验证,无法验证URL. 以及其他验证. 非常感谢
# 回答11
别客气. 很高兴它正在工作!
标签: Javascript