一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

PHP jQuery表單,帶驗證具體實現方法

 Email檢測,密碼重復檢測,可以用于表單發送的各種環境,例如發送反饋,注冊帳號

復制代碼 代碼如下:
<div id="container"> 
        <?if( isset($_POST['send']) && (!validateName($_POST['name']) || !validateEmail($_POST['email']) || !validatePasswords($_POST['pass1'], $_POST['pass2']) || !validateMessage($_POST['message']) ) ):?> 
                <div id="error"> 
                    <ul> 
                        <?if(!validateName($_POST['name'])):?> 
                            <li><strong>Invalid Name:</strong> We want names with more than 3 letters!</li> 
                        <?endif?> 
                        <?if(!validateEmail($_POST['email'])):?> 
                            <li><strong>Invalid E-mail:</strong> Stop cowboy! Type a valid e-mail please :P</li> 
                        <?endif?> 
                        <?if(!validatePasswords($_POST['pass1'], $_POST['pass2'])):?> 
                            <li><strong>Passwords are invalid:</strong> Passwords doesn't match or are invalid!</li> 
                        <?endif?> 
                        <?if(!validateMessage($_POST['message'])):?> 
                            <li><strong>Ivalid message:</strong> Type a message with at least with 10 letters</li> 
                        <?endif?> 
                    </ul> 
                </div> 
            <?elseif(isset($_POST['send'])):?> 
                <div id="error" class="valid"> 
                    <ul> 
                        <li><strong>Congratulations!</strong> All fields are OK ;)</li> 
                    </ul> 
                </div> 
        <?endif?> 

        <form method="post" id="customForm" action=""> 
            <div> 
                <label for="name">Name</label> 
                <input id="name" name="name" type="text" /> 
                <span id="nameInfo">What's your name?</span> 
            </div> 
            <div> 
                <label for="email">E-mail</label> 
                <input id="email" name="email" type="text" /> 
                <span id="emailInfo">Valid E-mail please, you will need it to log in!</span> 
            </div> 
            <div> 
                <label for="pass1">Password</label> 
                <input id="pass1" name="pass1" type="password" /> 
                <span id="pass1Info">At least 5 characters: letters, numbers and '_'</span> 
            </div> 
            <div> 
                <label for="pass2">Confirm Password</label> 
                <input id="pass2" name="pass2" type="password" /> 
                <span id="pass2Info">Confirm password</span> 
            </div> 
            <div> 
                <label for="message">Message</label> 
                <textarea id="message" name="message" cols="" rows=""></textarea> 
            </div> 
            <div> 
                <input id="send" name="send" type="submit" value="Send" /> 
            </div> 
        </form> 
    </div> 

validation.php

復制代碼 代碼如下:
<?php 
    function validateName($name){ 
        //if it's NOT valid 
        if(strlen($name) < 4) 
            return false; 
        //if it's valid 
        else 
            return true; 
    } 
    function validateEmail($email){ 
        return ereg("^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$", $email); 
    } 
    function validatePasswords($pass1, $pass2) { 
        //if DOESN'T MATCH 
        if(strpos($pass1, ' ') !== false)
            return false;
        //if are valid
        return $pass1 == $pass2 && strlen($pass1) > 5;
    }
    function validateMessage($message){
        //if it's NOT valid 
        if(strlen($message) < 10) 
            return false; 
        //if it's valid 
        else 
            return true; 
    } 
?> 

php技術PHP jQuery表單,帶驗證具體實現方法,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产成人自啪精品视频 | 亚洲乱码在线播放 | 国内精品伊人久久大香线焦 | 国产69久久精品成人看 | 成年美女黄网站色大片图片 | 四虎影视免费永久在线观看黄 | 丁香六月在线视频 | 亚洲综合狠狠 | 2020最新国产精品视频 | 99国产精品免费观看视频 | 91视频色| 视频在线观看一区二区 | 久久精品夜色国产 | 成年美女黄网站色视频大全免费 | 日韩成人免费一级毛片 | 欧美大片a特激情刺激 | 欧美亚洲综合一区 | 欧美亚洲国产精品久久久 | 国产原创麻豆精品视频 | 婷婷五色| 欧美激情一区 | 亚欧免费视频一区二区三区 | 久久入| 国产播放器一区 | 超级97人人公开视频 | 成 人网站免费 | 免费在线国产视频 | 国产一区福利 | 一本色道久久99一综合 | 久久久亚洲国产精品主播 | 天天舔天天爱 | 日本aⅴ永久免费网站www | 亚洲视频在线一区二区 | 91青青在线视频 | 在线看黄网站 | 四虎影视国产884a精品亚洲 | 亚洲图片小说网 | 久久国产精品只做精品 | 在线观看精品视频一区二区 | 伊人久久大香线蕉综合爱婷婷 | 男女男精品视频网站 |