亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 61
粉絲 0
評論 0
訪問量 73779
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
php用戶注冊
Pengsir
原創(chuàng)
954人瀏覽過

html代碼:

實例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>PHP表單驗證</title>
    <style>
        form{
            width: 500px;
            height: 600px;
            background-color: lightsalmon;
            margin: auto;
        }
        table{
            margin: auto;

        }
        table tr td{
            font-weight: bold;
            color: #222222;
            padding: 10px;

        }
    button{
        width: 100px;
        height: 30px;
        margin-left: 100px;
        background-color: #cccccc;
        font-weight: bolder;
    }
        button:hover{
            cursor: pointer;
            background-color: sandybrown;
            border: 1px solid red;
            border-radius: 20%;
        }
    </style>
</head>
<body>
<form>
    <table>
        <caption><h2>用戶注冊</h2></caption>
        <tr>
            <td>
                <label for="email">郵箱:</label>
            </td>
            <td>
                <input type="text" name="email" id="email">
            </td>
        </tr>
        <tr>
            <td><label for="password1">密碼:</label></td>
            <td><input type="password" name="password1" id="password1"></td>
        </tr>
        <tr>
            <td><label for="password2">確認(rèn):</label></td>
            <td><input type="password" name="password2" id="password2"></td>
        </tr>
        <tr>
            <td><label for="secret">性別:</label></td>
            <td>
                <input type="radio" name="sex" value="man">男
                <input type="radio" name="sex" value="woman">女
                <input type="radio" name="sex" value="secret" id="secret" checked>保密
            </td>
        </tr>
        <tr>
            <td><label>級別:</label></td>
            <td>
                <select name="level">
                <option value="0" selected>菜鳥程序猿</option>
                <option value="1">程序猿</option>
                <option value="2">攻城獅</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><label>語言:</label></td>
            <td>
                <input type="checkbox" name="language" value="php" checked>php
                <input type="checkbox" name="language" value="php">java
                <input type="checkbox" name="language" value="php">android
                <input type="checkbox" name="language" value="php">ios
            </td>
        </tr>
        <tr>
            <td><label for="introduction">簡介:</label></td>
            <td>
                <textarea name="introduction" id="introduction" cols="30" rows="10"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <button>提交</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script src="../jquery/jquery-3.2.1.min.js"></script>
<script>
    $('#email').blur(function () {
        //    $.post(url,data,success)
        $.post(
            'form.php?checked=email',
            'email='+$('#email').val(),
            function (data) {
                //郵箱驗證
                switch (data.status){
                    case 0:
                        $('td').find('span').remove()
                        $('#email').after('<span>').next().text(data.msg).css('color','red').prev().focus()
                        break
                    case 1:
                        $('td').find('span').remove()
                        $('#email').after('<span>').next().text(data.msg).css('color','red').prev().focus()
                        break
                    case 2:
                        $('td').find('span').remove()
                        $('#email').after('<span>').next().text(data.msg).css('color','green').prev()
                        break
                }
            },'json')
    })
    //密碼驗證
    $('#password1').blur(function () {
            //檢查郵箱輸入
        if ($('#email').val().length == 0) {
            return false;
        }
        $.post(
            'form.php?checked=password1',
            'password1='+$('#password1').val(),
            function (data) {
                if(data.status ==0){
                    $('#password1').after('<span>').next().text(data.msg).css('color','red').prev().focus()
                }
            },'json')
    })
    //確認(rèn)密碼驗證
    $('#password2').blur(function () {
        //檢查郵箱輸入
        if ($('#email').val().length == 0) {
            return false;
        }
        if ($('#password1').val().length == 0) {
            return false;
        }
        $.post(
            'form.php?checked=password2',
            {
                password1:$('#password1').val(),
                password2:$('#password2').val()
            },
            function (data) {
                    switch (data.status){
                        case 0:
                            $('td').find('span').remove()
                            $('#password2').after('<span>').next().text(data.msg).css('color','red').prev().focus()
                            break
                        case 1:
                            $('td').find('span').remove()
                            $('#password2').after('<span>').next().text(data.msg).css('color','red').prev().focus()
                            break
                        case 2:
                            $('td').find('span').remove()
                            $('#password2').after('<span>').next().text(data.msg).css('color','green')
                            break
                    }
            },'json')
    })
    //簡介
    $('#introduction').blur(function () {
        if($('#email').val().length ==0 || $('#password1').val().length ==0 ||$('#password1').val()!=$('#password2').val()){
            return false
        }
        $.post(
            'form.php?checked=introduction',
            {
                "introduction":$('#introduction').val()
            },
            function (data) {
                switch(data.status) {
                    case 0:
                        $('td').find('span').remove()
                        $('#introduction').after('<span>').next().text(data.msg).css('color','red').prev().focus()
                        break
                    case 1:
                        $('td').find('span').remove()
                        $('#introduction').after('<span>').next().text(data.msg).css('color','red').prev().focus()
                        break
                    case 2:
                        $('td').find('span').remove()
                        $('#introduction').after('<span>').next().text(data.msg).css('color','green')
                        break
                }
            },'json')
    })


</script>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例

php代碼:

實例

<?php
    switch ($_GET['checked']){
        //驗證郵箱
        case 'email':
            $email = $_POST['email'];
            if(empty($email)){
                exit(json_encode(['status'=>0,'msg'=>'郵箱不能為空']));
            }else if(in_array($email,['admin@php.com','php@php.cn'])){
                    exit(json_encode(['status'=>1,'msg'=>'郵箱已經(jīng)被使用']));
            }else {
                exit(json_encode(['status'=>2,'msg'=>'郵箱可用']));
            }
            break;
            //驗證密碼
        case 'password1':
            $password1 = $_POST['password1'];
            if(empty($password1)){
                exit(json_encode(['status'=>0,'msg'=>'密碼不為空']));
            }
            break;
            //驗證確認(rèn)密碼
        case 'password2':
            $password1=$_POST['password1'];
            $password2=$_POST['password2'];
            if(empty($password2)){
                exit(json_encode(['status'=>0,'msg'=>'確認(rèn)密碼不能為空']));
            }else if($password1 !=$password2){
                exit(json_encode(['status'=>1,'msg'=>'兩次密碼不一致']));
            }else{
                exit(json_encode(['status'=>2,'msg'=>'驗證通過']));
            }
            break;
            //簡介
        case 'introduction':
            $introduction=$_POST['introduction'];
            if(empty($introduction)){
                exit(json_encode(['status'=>0,'msg'=>'簡介不能為空']));
            }else if(strlen($introduction)<20){
                exit(json_encode(['status'=>1,'msg'=>'簡介字?jǐn)?shù)不能小于20個字']));
            }else{
                exit(json_encode(['status'=>2,'msg'=>'簡介說明已完成']));
            }
    }

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例

運行效果圖:

php用戶注冊案例.png

批改狀態(tài):未批改

老師批語:
本博文版權(quán)歸博主所有,轉(zhuǎn)載請注明地址!如有侵權(quán)、違法,請聯(lián)系admin@php.cn舉報處理!
全部評論 文明上網(wǎng)理性發(fā)言,請遵守新聞評論服務(wù)協(xié)議
0條評論
作者最新博文
關(guān)于我們 免責(zé)申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!
關(guān)注服務(wù)號 技術(shù)交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費學(xué)