用于url验证的java脚本

我只是希望对网站URL检查的验证. 但是它不应从http://开始(例如http://www.yahoo.com) 它应该从WW.(示例www.yahhoo.com) 提前

# 回答1

PLESE固定场

选择 | 换行 | 行号
  1. if(document.frmRegister.WebSite.value!="")
  2.       {
  3.              if (document.frmRegister.WebSite.value.indexOf ('www', 0) == -1 || document.frmRegister.WebSite.value.length < 10)
  4.              {
  5.                   if(document.frmRegister.WebSite.value.indexOf ('.com', 0) == -1 || document.frmRegister.WebSite.value.length < 10) 
  6.                     {
  7.                        alert ("Enter a valid URL")
  8.                        document.frmRegister.WebSite.focus();
  9.                        return false;
  10.                      }
  11.              }
  12.          }
# 回答2

选择 | 换行 | 行号
  1. if(document.frmRegister.WebSite.value!="")
  2.       {
  3.              if (document.frmRegister.WebSite.value.indexOf ('www', 0) == -1 || document.frmRegister.WebSite.value.length < 10)
  4.              {
  5.                   if(document.frmRegister.WebSite.value.indexOf ('.com', 0) == -1 || document.frmRegister.WebSite.value.length < 10) 
  6.                     {
  7.                        alert ("Enter a valid URL")
  8.                        document.frmRegister.WebSite.focus();
  9.                        return false;
  10.                      }
  11.              }
  12.          }
# 回答3

嗨,我是这个网站的新事物. 请帮助我,我坚持网站验证BCOZ, 我想以这种方式进行验证, 用户只能在(http://www.test.com)或任何一个(www.test.com)中输入网站. 接受此类型的条目显示警报" PLZ以正确的方式输入网站", 我使用了您的样式,但是当我们在多次中输入点(.) (http://wwwwww.c....test....com)或(wwwwww .......................................................................................................... ... com)
# 回答4

你好, 这可能会帮助您...

选择 | 换行 | 行号
  1.             function isURL ( txtId ){
  2.  
  3.                   var string = document.getElementById(txtId).value;    
  4.  
  5.                   if ( string.search(/^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/) != -1 ){
  6.                             alert('Valid URL');
  7.                         return true;
  8.                   }
  9.  
  10.  
  11.                   if ( string.search(/^[http://]+[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/) != -1 ){
  12.                             alert('valid URL');
  13.                         return true;
  14.                   }
  15.  
  16.                   alert('Not a valid URL');
  17.                   document.getElementById(txtId).select();
  18.                   document.getElementById(txtId).focus();        
  19.                   return false;
  20.  
  21.             }
  22.  
  23.  

问候,

# 回答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,但我再次坚持下去.

选择 | 换行 | 行号
  1. if( (website != "") || (website != null) )    
  2.     {
  3.         if (website.indexOf ('http://', 0) == -1 )
  4.         {    
  5.             if (website.indexOf ('www.', 0) == -1 || website.length < 10)
  6.                {    
  7.                    if(website.indexOf ('.com', 0) == -1 || website.length < 10)
  8.                 {
  9.                     alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
  10.                     document.filmsForm.url.focus();
  11.                     document.filmsForm.url.value = "" ;
  12.                     return false;
  13.                 }
  14.                }
  15.  
  16.             var split = website.split("\.");
  17.  
  18.             if(isNaN(split[0]))
  19.             {
  20.                 if( (split[0].length > 3) || (split[0].length < 2) )
  21.                 {
  22.                     alert("The Length Of www Must Be '3' !");
  23.                       document.filmsForm.url.focus();
  24.                     document.filmsForm.url.value = "" ;
  25.                       return false;
  26.  
  27.                 }
  28.             }else 
  29.             {
  30.                 alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
  31.                 document.filmsForm.url.focus();
  32.                 document.filmsForm.url.value = "" ;
  33.                 return false;
  34.             }
  35.  
  36.  
  37.         } else {
  38.  
  39.             if (website.indexOf('www.', 0) == -1 || website.length < 10)
  40.                {    
  41.                    if(website.indexOf('.com', 0) == -1 || website.length < 10)
  42.                 {
  43.                     alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
  44.                     document.filmsForm.url.focus();
  45.                     document.filmsForm.url.value = "" ;
  46.                     return false;
  47.                 }
  48.                }
  49.  
  50.             var splitfromhttp = website.split("http://");
  51.  
  52.             var splitfromdot = splitfromhttp[1].split("\.");
  53.  
  54.             if(isNaN(splitfromdot[0]))
  55.             {
  56.                 if( (splitfromdot[0].length > 3) || (splitfromdot[0].length < 2) )
  57.                 {
  58.                     alert("The Length Of www Must Be '3' !");
  59.                       document.filmsForm.url.focus();
  60.                     document.filmsForm.url.value = "" ;
  61.                       return false;
  62.  
  63.                 }
  64.             }else 
  65.             {
  66.                 alert ("Enter a Website name Like 'http://www.test.com' Or 'www.test.com' !")
  67.                 document.filmsForm.url.focus();
  68.                 document.filmsForm.url.value = "" ;
  69.                 return false;
  70.             }
  71.  
  72.         }       
  73.     }
  74.  

- >

# 回答7

与其进行很多检查,不如使用一个正则表达式,例如:

选择 | 换行 | 行号
  1. /^(http://)?www\.[a-z]+\.com$/gi

一个非常简单的一个只能匹配字母URL,而不匹配具有数字,连字符等的字母URL.它也只能匹配.com,这似乎是您正在检查的.

# 回答8

嘿,我在软件(regesxbilder)上测试此正则表达式,但表明正则表达式是佩戴的.
# 回答9

那是我在没有测试的情况下想到的一个快速示例. 您需要逃脱前锋的斜线:

选择 | 换行 | 行号
  1. /^(http:\/\/)?www\.[a-z]+\.com$/gi

请注意,这绝不是完整的测试. 为此,您将需要更复杂的东西.

# 回答10

thanx我通过正则表达方式得到了解决方案....是的! 将其(正则表达式)正确验证,无法验证URL. 以及其他验证. 非常感谢
# 回答11

别客气. 很高兴它正在工作!

标签: Javascript

添加新评论