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

前端之家收集整理的这篇文章主要介绍了正则验证密码、邮箱、电话号码、手机号码、QQ、MSN、网址、IP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

注册时的一些验证:

 
 
  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <htmlxmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <Metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/>
  5. <title></title>
  6. <scripttype="text/javascript">
  7. @H_502_56@//window.onload=toSubmit;
  8. @H_502_56@//window.onload=validateEmail;
  9. @H_502_56@//window.onload=validatePhone;
  10. @H_502_56@//window.onload=validateMobilePhone;
  11. @H_502_56@//window.onload=validateQQ;
  12. @H_502_56@//window.onload=validateMSN;
  13. @H_502_56@//window.onload=validateNet;
  14. window.onload=validateIP;
  15. @H_502_56@/**验证是不是字母和数字的组合!==4-14位字母数字的组合=注册时对用户名的验证*/
  16. functiontoSubmit(){
  17. varparam=/^[0-9a-zA-Z]*([a-zA-Z]+[0-9]+|[0-9]+[a-zA-Z]+)[0-9a-zA-Z]*$/;
  18. varusername="HNA123";
  19. varresult=param.test(username);
  20. alert(result);
  21. }
  22. @H_502_56@/**对Email的验证*/
  23. functionvalidateEmail(){
  24. varregEmail=/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  25. varemail="tt23omom@125.com";
  26. varresult=regEmail.test(email);
  27. alert(result);
  28. }
  29. @H_502_56@/**验证电话号码==========。*/
  30. functionvalidatePhone(){
  31. varregPhone=/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
  32. varphone="021-60825088";@H_502_56@//"0427-7531992";//"76423865";
  33. varresult=regPhone.test(phone);
  34. alert(result);
  35. }
  36. @H_502_56@/**验证手机号码-----*/
  37. functionvalidateMobilePhone(){
  38. varregMobile=/^1[3|4|5|6|7|8|9][0-9]{1}[0-9]{8}$/;
  39. varmobile="13877794164";
  40. varresult=regMobile.test(mobile);
  41. alert(result);
  42. }
  43. @H_502_56@/**验证QQ号*/
  44. functionvalidateQQ(){
  45. varregQQ=/^[1-9]\d{4,8}$/;
  46. varqq="294851313";
  47. varresult=regQQ.test(qq);
  48. alert(result);
  49. }
  50. @H_502_56@/**验证MSN*/
  51. functionvalidateMSN(){
  52. varregEmail=/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  53. varmsn="12345@liehuo.net";
  54. varresult=regEmail.test(msn);
  55. alert(result);
  56. }
  57. @H_502_56@/**验证网址============以http://开头*/
  58. functionvalidateNet(){
  59. varregNet=/^http:\/\/([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=]*)?$/;
  60. varurl="http://game.baidu.com";
  61. varresult=regNet.test(url);
  62. alert(result);
  63. }
  64. @H_502_56@/**验证IP*/
  65. functionvalidateIP(){
  66. varcheckIp=/^(\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])$/;
  67. varip="192.168.25.103";
  68. varresult=checkIp.test(ip);
  69. alert(result);
  70. }
  71. </script>
  72. </head>
  73. <body>
  74. </body>
  75. </html>

猜你在找的正则表达式相关文章