•  \r\n \r\n \r\n \r\n賬戶基本信息<\/td> \r\n<\/tr> \r\n \r\n \r\n \r\n \r\n賬戶安全設(shè)置<\/td> \r\n<\/tr> \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
    <abbr id="fuzvr"></abbr>
  • 登錄賬號(hào):<\/td> \r\n<\/span><\/td> \r\n<\/tr> \r\n
    昵稱:<\/td> \r\n<\/span><\/td> \r\n<\/tr> \r\n
    性別:<\/td> \r\n男 \r\n女 \r\n<\/span><\/td> \r\n<\/tr> \r\n
    登錄密碼:<\/td> \r\n<\/span><\/td> \r\n<\/tr> \r\n
    確認(rèn)登錄密碼:<\/td> \r\n<\/span><\/td> \r\n<\/tr> \r\n
    真實(shí)姓名:<\/td> \r\n<\/span><\/td> \r\n<\/tr> \r\n
    身份證號(hào):<\/td> \r\n<\/span><\/td> \r\n<\/tr> \r\n
    郵箱地址:<\/td> \r\n<\/span><\/td> \r\n<\/tr> \r\n
    驗(yàn)證碼<\/td> \r\n \r\n \r\n<\/span> \r\n<\/span> \r\n<\/td> \r\n<\/tr> \r\n
    <\/td> \r\n<\/td> \r\n<\/tr> \r\n<\/table> \r\n<\/form> \r\n

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    Home Backend Development PHP Tutorial Ajax and PHP regular expression validation form and verification code

    Ajax and PHP regular expression validation form and verification code

    Feb 03, 2017 pm 05:48 PM

    Pattern matching character:

    \: Escape character For example: \b escapes b

    ^: Regular expression start symbol

    $: regular expression end symbol

    *: matches the previous character appearing 0 or n times

    +: matches the previous character appearing 1 or n times

    ?: Matches the previous character 0 or 1 times

    .: Matches all single characters except newlines

    |: or means, for example, x|y matches x or y

    {n}: matches the first n characters

    {n,m}: matches at least n up to m previous characters

    [xyz]: matches any character in the brackets

    [^xyz]: matches any character except the brackets Characters are equivalent to [0-9]

    \w: Match any number or letter or underscore, which is equivalent to [A-Za-z0-9_]

    \d: Match any number between 0--9

    Pattern modifier:

    i: Ignore case

    Examples of commonly used regular expressions:

    //The user name consists of 6-18 digits of alphanumeric characters and underscores, and cannot begin with a number

    var r_name=/^[a-z]\w {5,17}$/i

    //The password length cannot be less than six characters

    var r_pwd=/^\w{6,}$/

    //All general email addresses

    var r_eamil=/^\w+@\w+(\.)\w+$/

    //Match a QQ email address

    //861745122@qq.com
    var r_qq_email=/^\d{5,}@qq(\.)com$/

    //Match a 163 email address

    var r_163_email=/^\w+@163(\.)com$/

    //Match A suffix might be .com|.net|.cn|.edu

    var email=/^\w+@\w+(\.)com|net|cn|edu$/

    //Requires a valid age group

    var r_age=/^\d{1,2}$/

    //if (age>=18&&age《=100)

    //Verify mobile phone number: 11 digits starting with 13 15 18

    var r_tel=/^1[3,5, 8]\d{9}$/

    //Verify the 18-digit or 17-digit ID number plus an X

    var r_s=/^\d{18 }|\d{17}x$/i

    //Verify Chinese var reg=/^[\u4e00-\u9fa5]{2,17}$/

    //php

    $reg = "/^[\x{4e00}-\x{9fa5}]$/u"

    <span style="font-size:24px;">下面是一個(gè)例子:</span> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 
    <title></title> 
    <script type="text/javascript" src="public.js"></script> 
    </head> 
    <body onload="yanzheng(this)"> 
    <form method="post" action="info_2.php" onsubmit="return check_all()"> 
    <table> 
    <tr> 
    <td colspan="2">賬戶基本信息</td> 
    </tr> 
    <tr> 
    <td>登錄賬號(hào):</td> 
    <td><input type="text" name="zhanghao" onblur="check_zhanghao(this)"><span name="sp1"></span></td> 
    </tr> 
    <tr> 
    <td>昵稱:</td> 
    <td><input type="text" name="nicheng" onblur="check_nicheng(this)"><span name="sp2"></span></td> 
    </tr> 
    <tr> 
    <td>性別:</td> 
    <td><input type="radio" name="sex" value="男"onclick="check_sex()">男 
    <input type="radio" name="sex" value="女"onclick="check_sex()">女 
    <span id="sp3"></span></td> 
    </tr> 
    <tr> 
    <td colspan="2">賬戶安全設(shè)置</td> 
    </tr> 
    <tr> 
    <td>登錄密碼:</td> 
    <td><input type="password" name="pwd" onblur="check_pwd(this)"><span name="sp4"></span></td> 
    </tr> 
    <tr> 
    <td>確認(rèn)登錄密碼:</td> 
    <td><input type="password" name="repwd" onblur="check_repwd(this)"><span name="sp5"></span></td> 
    </tr> 
    <tr> 
    <td>真實(shí)姓名:</td> 
    <td><input type="text" name="username" onblur="check_username(this)"><span name="sp6"></span></td> 
    </tr> 
    <tr> 
    <td>身份證號(hào):</td> 
    <td><input type="text" name="idcard" onblur="check_idcard(this)"><span name="sp7"></span></td> 
    </tr> 
    <tr> 
    <td>郵箱地址:</td> 
    <td><input type="text" name="email" onblur="check_email(this)"><span name="sp8"></span></td> 
    </tr> 
    <tr> 
    <td>驗(yàn)證碼</td> 
    <td><input type="text" id="number" onblur="check_number()"> 
    <input type="button" onclick="yanzheng()" value="獲取驗(yàn)證碼" > 
    <span id="sp10"></span> 
    <span id="sp9"></span> 
    </td> 
    </tr> 
    <tr> 
    <td></td> 
    <td><input type="submit" value="免費(fèi)注冊(cè)"></td> 
    </tr> 
    </table> 
    </form> 
    <script type="text/javascript"> 
    //驗(yàn)證登錄賬號(hào) 
    function check_zhanghao(obj){ 
    var sp1=$(&#39;sp1&#39;); 
    if(obj.value==&#39;&#39;){ 
    sp1.innerHTML=&#39;登錄賬號(hào)不能為空&#39;; 
    sp1.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    var reg=/^\w{5,10}$/i; 
    if(reg.test(obj.value)){ 
    sp1.innerHTML=&#39;正確&#39;; 
    sp1.style.color=&#39;green&#39;; 
    return true; 
    }else{ 
    sp1.innerHTML=&#39;登錄賬號(hào)5-10字符&#39;; 
    sp1.style.color=&#39;red&#39;; 
    return false; 
    } 
    }return true; 
    } 
    //驗(yàn)證昵稱 
    function check_nicheng(obj){ 
    var sp2=$(&#39;sp2&#39;); 
    if(obj.value==&#39;&#39;){ 
    sp2.innerHTML=&#39;登錄賬號(hào)不能為空&#39;; 
    sp2.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    var reg=/^\w{5,10}$/i; 
    if(reg.test(obj.value)){ 
    sp2.innerHTML=&#39;正確&#39;; 
    sp2.style.color=&#39;green&#39;; 
    return true; 
    }else{ 
    sp2.innerHTML=&#39;昵稱5-10字符&#39;; 
    sp2.style.color=&#39;red&#39;; 
    return false; 
    } 
    }return true; 
    } 
    //驗(yàn)證密碼 
    function check_pwd(obj2){ 
    var sp4=$(&#39;sp4&#39;); 
    if(obj2.value==&#39;&#39;){ 
    sp4.innerHTML=&#39;密碼不能為空&#39;; 
    sp4.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    var reg=/^\w{6,}$/; 
    if(reg.test(obj2.value)){ 
    sp4.innerHTML=&#39;正確&#39;; 
    sp4.style.color=&#39;green&#39;; 
    return true; 
    }else{ 
    sp4.innerHTML=&#39;格式不正確&#39;; 
    sp4.style.color=&#39;red&#39;; 
    return false; 
    } 
    }return true; 
    } 
    //驗(yàn)證確認(rèn)密碼 
    function check_repwd(obj3){ 
    var sp5=$(&#39;sp5&#39;); 
    var pwd=$(&#39;pwd&#39;); 
    var repwd=$(&#39;repwd&#39;); 
    if(obj3.value==&#39;&#39;){ 
    sp5.innerHTML=&#39;密碼不能為空&#39;; 
    sp5.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    if(obj3.value==pwd.value){ 
    sp5.innerHTML=&#39;正確&#39;; 
    sp5.style.color=&#39;green&#39;; 
    return true; 
    }else{ 
    sp5.innerHTML=&#39;確認(rèn)密碼和密碼不一致&#39;; 
    sp5.style.color=&#39;red&#39;; 
    return false; 
    } 
    }return true; 
    } 
    //驗(yàn)證性別 
    num2=0; 
    function check_sex(){ 
    var sex=document.getElementsByName(&#39;sex&#39;); 
    // var sp4=document.getElementById(&#39;sp4&#39;) 
    for(var i=0;i<sex.length;i++){ 
    if(sex[i].checked==true){ 
    num2=num2+1; 
    } 
    } 
    //alert(num2); 
    if(num2!=0){ 
    sp3.innerHTML=&#39;√&#39;; 
    sp3.style.color=&#39;green&#39;; 
    return true; 
    }else{ 
    sp3.innerHTML=&#39;性別不能為空&#39;; 
    sp3.style.color=&#39;red&#39;; 
    return false; 
    } 
    } 
    //驗(yàn)證姓名 
    function check_username(obj){ 
    var sp6=$(&#39;sp6&#39;); 
    if(obj.value==""){ 
    sp6.innerHTML=&#39;用戶名不能為空&#39;; 
    sp6.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    var reg=/^[\u4e00-\u9fa5]{2,3}$/; 
    if(!reg.test(obj.value)){ 
    sp6.innerHTML=&#39;用戶名應(yīng)該2-3個(gè)漢字&#39;; 
    sp6.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    sp6.innerHTML=&#39;√&#39;; 
    sp6.style.color=&#39;green&#39;; 
    return true; 
    } 
    } 
    return true; 
    } 
    //驗(yàn)證郵箱 
    function check_email(obj5){ 
    var sp8=$(&#39;sp8&#39;); 
    if(obj5.value==&#39;&#39;){ 
    sp8.innerHTML=&#39;郵箱不能為空&#39;; 
    sp8.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    var reg=/^(\w+@\w+(\.)com|net|cn)$/; 
    if(reg.test(obj5.value)){ 
    sp8.innerHTML=&#39;正確&#39;; 
    sp8.style.color=&#39;green&#39;; 
    return true; 
    }else{ 
    sp8.innerHTML=&#39;格式不正確&#39;; 
    sp8.style.color=&#39;red&#39;; 
    return false; 
    }return true; 
    } 
    } 
    //驗(yàn)證身份證號(hào) 
    function check_idcard(obj9){ 
    var sp7=$(&#39;sp7&#39;); 
    if(obj9.value==&#39;&#39;){ 
    sp7.innerHTML=&#39;身份證號(hào)不能為空&#39;; 
    sp7.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    var reg=/^\d{18}|\d{17}x$/i; 
    if(reg.test(obj9.value)){ 
    sp7.innerHTML=&#39;正確&#39;; 
    sp7.style.color=&#39;green&#39;; 
    return true; 
    }else{ 
    sp7.innerHTML=&#39;格式不正確&#39;; 
    sp7.style.color=&#39;red&#39;; 
    return false; 
    }return true; 
    } 
    } 
    //生成驗(yàn)證碼 
    function yanzheng(){ 
    var sp9=document.getElementById(&#39;sp9&#39;); 
    var str1=""; 
    for(var i=1;i<=4;i++){ 
    str1=str1+parseInt(Math.random()*10); 
    sp9.innerHTML=str1; 
    } 
    } 
    //驗(yàn)證驗(yàn)證碼 
    function check_number(){ 
    var number=document.getElementById(&#39;number&#39;).value 
    var sp10=document.getElementById(&#39;sp10&#39;) 
    var sp9=document.getElementById(&#39;sp9&#39;); 
    if(number==""){ 
    sp10.innerHTML=&#39;驗(yàn)證碼不能為空&#39;; 
    sp10.style.color=&#39;red&#39;; 
    return false; 
    }else{ 
    if(number!=sp9.innerHTML){ 
    sp10.innerHTML=&#39;驗(yàn)證碼和你寫的不一致&#39;; 
    sp10.style.color=&#39;red&#39;; 
    return false; 
    } else{ 
    sp10.innerHTML=&#39;√&#39;; 
    sp10.style.color=&#39;green&#39;; 
    return true;} 
    return true; 
    } 
    } 
    function check_all(){ 
    if(check_zhanghao($(&#39;zhanghao&#39;)) & check_nicheng($(&#39;nicheng&#39;)) & check_pwd($(&#39;pwd&#39;)) & check_repwd($(&#39;repwd&#39;)) & check_sex()& check_username($(&#39;username&#39;)) & check_idcard($(&#39;idcard&#39;)) &check_email($(&#39;email&#39;)) & check_number() ){ 
    return true;} 
    else{ return false;} 
    } 
    </script> 
    </body> 
    </html>

    php regular verification

    <?php 
    header("content-type:text/html;charset=utf8"); 
    //var_dump($_POST);die; 
    //array(5) { ["uname"]=> string(9) "劉偉超" ["uqq"]=> string(10) "1111111111" ["uemail"]=> string(12) "66555@qq.com" ["utel"]=> string(11) "15863162320" ["uinfo"]=> string(48) "地方開(kāi)始放假開(kāi)放活動(dòng)健康的話概括" } 
    empty($_POST["uname"])?$uname="":$uname=$_POST["uname"]; 
    empty($_POST["uemail"])?$uemail="":$uemail=$_POST["uemail"]; 
    empty($_POST["utel"])?$utel="":$utel=$_POST["utel"]; 
    empty($_POST["uqq"])?$uqq="":$uqq=$_POST["uqq"]; 
    empty($_POST["uinfo"])?$uinfo="":$uinfo=$_POST["uinfo"]; 
    //驗(yàn)證姓名 
    $reg="/^[\x{4e00}-\x{9fa5}]{2,3}$/u"; 
    if(!preg_match($reg,$uname)){ 
    echo "用戶名應(yīng)該2-3個(gè)漢字";die; 
    //header("refresh:1;url=form.html"); 
    } 
    //驗(yàn)證郵箱 
    $reg="/^(\w+@\w+(\.)com|net|cn)$/"; 
    if(!preg_match($reg,$uemail)){ 
    echo "郵箱必須含有@,且以com結(jié)尾";header("refresh:1;url=form.html"); die; 
    } 
    //驗(yàn)證座機(jī)號(hào) 
    $reg="/^\d{11}$/"; 
    if(!preg_match($reg,$utel)){ 
    echo "座機(jī)號(hào)以010-22222222格式";header("refresh:1;url=form.html"); die; 
    } 
    //驗(yàn)證QQ號(hào) 
    $reg="/^\d{5,11}$/"; 
    if(!preg_match($reg,$uqq)){ 
    echo "qq必須是5-11位純數(shù)字";header("refresh:1;url=form.html"); die; 
    } 
    //驗(yàn)證簡(jiǎn)介 
    /*$reg="/^[\x{4e00}-\x{9fa5}]{10,100}\W+/u"; 
    if(!preg_match($reg,$uinfo)){ 
    echo "簡(jiǎn)介應(yīng)該10-100個(gè)漢字";die; 
    //header("refresh:1;url=form.html"); 
    } 
    */
    //連接數(shù)據(jù)庫(kù) 
    $link=mysql_connect(&#39;127.0.0.1&#39;,&#39;root&#39;,&#39;root&#39;)or die("連接失敗"); 
    //選擇數(shù)據(jù)庫(kù) 
    mysql_select_db(&#39;kaoshi&#39;,$link); 
    //設(shè)置字符集 
    mysql_query("set names utf8"); 
    //寫sql語(yǔ)句 
    $sql="insert into zhuce(c_name,c_qq,c_email,c_tel,c_info) values(&#39;$uname&#39;,&#39;$uqq&#39;,&#39;$uemail&#39;,&#39;$utel&#39;,&#39;$uinfo&#39;)"; 
    //echo $sql;die; 
    $rel=mysql_query($sql); 
    if($rel){ 
    echo "注冊(cè)成功";header("refresh:1;url=show.php"); 
    }else{echo "注冊(cè)失敗";header("refresh:1;url=form.html");} 
    ?>

    The above is the Ajax and PHP regular expression verification form and verification code introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. . I would also like to thank you all for your support of the PHP Chinese website!

    For more articles related to Ajax and PHP regular expression verification forms and verification codes, please pay attention to the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How do I implement authentication and authorization in PHP? How do I implement authentication and authorization in PHP? Jun 20, 2025 am 01:03 AM

    TosecurelyhandleauthenticationandauthorizationinPHP,followthesesteps:1.Alwayshashpasswordswithpassword_hash()andverifyusingpassword_verify(),usepreparedstatementstopreventSQLinjection,andstoreuserdatain$_SESSIONafterlogin.2.Implementrole-basedaccessc

    How can you handle file uploads securely in PHP? How can you handle file uploads securely in PHP? Jun 19, 2025 am 01:05 AM

    To safely handle file uploads in PHP, the core is to verify file types, rename files, and restrict permissions. 1. Use finfo_file() to check the real MIME type, and only specific types such as image/jpeg are allowed; 2. Use uniqid() to generate random file names and store them in non-Web root directory; 3. Limit file size through php.ini and HTML forms, and set directory permissions to 0755; 4. Use ClamAV to scan malware to enhance security. These steps effectively prevent security vulnerabilities and ensure that the file upload process is safe and reliable.

    What are the differences between == (loose comparison) and === (strict comparison) in PHP? What are the differences between == (loose comparison) and === (strict comparison) in PHP? Jun 19, 2025 am 01:07 AM

    In PHP, the main difference between == and == is the strictness of type checking. ==Type conversion will be performed before comparison, for example, 5=="5" returns true, and ===Request that the value and type are the same before true will be returned, for example, 5==="5" returns false. In usage scenarios, === is more secure and should be used first, and == is only used when type conversion is required.

    How do I perform arithmetic operations in PHP ( , -, *, /, %)? How do I perform arithmetic operations in PHP ( , -, *, /, %)? Jun 19, 2025 pm 05:13 PM

    The methods of using basic mathematical operations in PHP are as follows: 1. Addition signs support integers and floating-point numbers, and can also be used for variables. String numbers will be automatically converted but not recommended to dependencies; 2. Subtraction signs use - signs, variables are the same, and type conversion is also applicable; 3. Multiplication signs use * signs, which are suitable for numbers and similar strings; 4. Division uses / signs, which need to avoid dividing by zero, and note that the result may be floating-point numbers; 5. Taking the modulus signs can be used to judge odd and even numbers, and when processing negative numbers, the remainder signs are consistent with the dividend. The key to using these operators correctly is to ensure that the data types are clear and the boundary situation is handled well.

    How can you interact with NoSQL databases (e.g., MongoDB, Redis) from PHP? How can you interact with NoSQL databases (e.g., MongoDB, Redis) from PHP? Jun 19, 2025 am 01:07 AM

    Yes, PHP can interact with NoSQL databases like MongoDB and Redis through specific extensions or libraries. First, use the MongoDBPHP driver (installed through PECL or Composer) to create client instances and operate databases and collections, supporting insertion, query, aggregation and other operations; second, use the Predis library or phpredis extension to connect to Redis, perform key-value settings and acquisitions, and recommend phpredis for high-performance scenarios, while Predis is convenient for rapid deployment; both are suitable for production environments and are well-documented.

    How do I stay up-to-date with the latest PHP developments and best practices? How do I stay up-to-date with the latest PHP developments and best practices? Jun 23, 2025 am 12:56 AM

    TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

    What is PHP, and why is it used for web development? What is PHP, and why is it used for web development? Jun 23, 2025 am 12:55 AM

    PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

    How to set PHP time zone? How to set PHP time zone? Jun 25, 2025 am 01:00 AM

    TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

    See all articles