zoukankan      html  css  js  c++  java
  • JavaScript: RegExp check UserName

    Function : We can use regular expressions to check user input data formats.

    Homework: Check user input meets the requirements or not.

    I use regular expressions to check the users Chinese name , nickname and their phonenumber.

    This is this projiect's appearance:

    Below is this project's code:

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <script>
     8         function user(){
     9             var user=document.getElementById("user").value;
    10             var User=/[u4e00-u9fa5]{2,5}/; 
    11             if(User.test(user)) alert("格式正确");
    12             else alert("格式错误");
    13         }
    14         function Name(){
    15             var name=document.getElementById("Name").value;
    16             var Name=/^[a-zA-z][a-zA-Z0-9_]{2,9}$/;   
    17             if(Name.test(name)) alert("格式正确");
    18             else alert("格式错误");
    19         }
    20         function Phone(){
    21             var phone=document.getElementById("Phone").value;
    22             var Phone=/^[+]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){4,12})+$/;   
    23             if(Phone.test(phone)) alert("格式正确");
    24             else alert("格式错误");
    25         }
    26     </script>
    27  <body>
    28         用户名:<input type="text" name="user" id="user">
    29         <input type="button" value="检查" onclick="user()"><br>要求:两个中文字符以上<br><br>
    30&nbsp;&nbsp;&nbsp;称:<input type="text" name="Name" id="Name">
    31         <input type="button" value="检查" onclick="Name()"><br>要求:字母开头的3-10位昵称,可含有字母或下划线<br><br>
    32         手机号:<input type="text" name="Phone" id="Phone" >
    33         <input type="button" value="检查" onclick="Phone()"><br>要求:5位数字以上   
    34 </body>
    35 </html>
  • 相关阅读:
    Maven 那点事儿
    maven pom文件详解
    Maven Missing artifact jar
    JVM调优总结 -Xms -Xmx -Xmn -Xss
    LoadRunner做性能测试 从设计到分析执行
    linux内核参数注释与优化
    tcpdump详解
    [转]Linux服务器上11种网络连接状态 和 TCP三次握手/四次挥手详解
    MSM--Memcached_Session_Manager介绍及使用
    黏性Session和非黏性Session
  • 原文地址:https://www.cnblogs.com/chenzhihong294/p/9867826.html
Copyright © 2011-2022 走看看