正则验证密码、邮箱、电话号码、手机号码、QQ、MSN、网址、IP

 注册时的一些验证:

 

  
  
  
  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4.     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 
  5.     <title></title> 
  6.     <script type="text/javascript"
  7.         //window.onload = toSubmit; 
  8.         //window.onload = validateEmail; 
  9.         //window.onload = validatePhone; 
  10.         //window.onload = validateMobilePhone; 
  11.         //window.onload = validateQQ; 
  12.         //window.onload = validateMSN; 
  13.         //window.onload = validateNet; 
  14.         window.onload = validateIP; 
  15.          
  16.          
  17.         /**验证是不是字母和数字的组合!==4-14位字母数字的组合=注册时对用户名的验证*/ 
  18.         function toSubmit() { 
  19.             var param = /^[0-9a-zA-Z]*([a-zA-Z]+[0-9]+|[0-9]+[a-zA-Z]+)[0-9a-zA-Z]*$/; 
  20.             var username = "HNA123"
  21.              
  22.             var result = param.test(username); 
  23.              
  24.             alert(result); 
  25.         } 
  26.          
  27.         /**对Email的验证*/ 
  28.         function validateEmail() { 
  29.             var regEmail =  /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;  
  30.              
  31.             var email = "[email protected]"
  32.             var result = regEmail.test(email); 
  33.              
  34.             alert(result); 
  35.         } 
  36.          
  37.         /**验证电话号码==========。*/ 
  38.         function validatePhone() { 
  39.             var regPhone = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/; 
  40.             var phone = "021-60825088";//"0427-7531992"; //"76423865"; 
  41.             var result = regPhone.test(phone); 
  42.             alert(result); 
  43.         } 
  44.          
  45.         /**验证手机号码-----*/ 
  46.         function validateMobilePhone() { 
  47.             var regMobile = /^1[3|4|5|6|7|8|9][0-9]{1}[0-9]{8}$/; 
  48.             var mobile = "13877794164"
  49.             var result = regMobile.test(mobile); 
  50.             alert(result); 
  51.         } 
  52.          
  53.         /**验证QQ号*/ 
  54.         function validateQQ() { 
  55.             var regQQ =/^[1-9]\d{4,8}$/; 
  56.             var qq = "294851313"
  57.             var result = regQQ.test(qq); 
  58.             alert(result); 
  59.         } 
  60.          
  61.         /**验证MSN*/ 
  62.         function validateMSN() { 
  63.             var regEmail =  /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;  
  64.             var msn = "[email protected]"
  65.             var result = regEmail.test(msn); 
  66.             alert(result); 
  67.         } 
  68.          
  69.         /**验证网址============以http://开头*/ 
  70.         function validateNet() { 
  71.             var regNet = /^http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/; 
  72.             var url = "http://game.baidu.com"
  73.             var result = regNet.test(url); 
  74.             alert(result); 
  75.         } 
  76.          
  77.         /**验证IP*/ 
  78.         function validateIP() { 
  79.             var checkIp = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; 
  80.             var ip = "192.168.25.103"
  81.             var result = checkIp.test(ip); 
  82.             alert(result); 
  83.         } 
  84.     </script> 
  85. </head> 
  86. <body> 
  87.      
  88. </body> 
  89. </html> 

 

你可能感兴趣的:(JS验证邮箱,验证手机号码,验证电话号码,正则验证邮箱)