php 注册表单验证,PHP+AJAX之用户注册表单验证->0416

注册界面

html>

content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

用户注册
用户注册
邮箱
密码
确认
性别

保密

级别

初级

中级

高级

语言

java

c

php

简介

提交

运行实例 »

点击 "运行实例" 按钮查看在线实例

regiess.css

table {

margin: 0 auto;

background-color: #BB996C;

box-shadow: 10px 10px 10px #BB996C;

}

caption {

font-size: 1.1em;

color: #00CC66;

background: #BB996C;

}

textarea {

resize: none;

}

#buttontd {

text-align: center;

}

button {

border-radius: 5px 5px 5px 5px;

box-shadow: 2px 2px 2px #00a2d4;

}

运行实例 »

点击 "运行实例" 按钮查看在线实例

regiess.js

/医院

* 在执行对应操作前执行上个对象非空判断。否则会出现死循环bug程序不停执行循环请求结果都是null

*/

$(document).ready(function () {

$('#email').blur(function () {

if ($('#email').val().length == 0) {

$('#email').next().remove();

$('#email').after('').next().text("邮箱不能为null").css("color","red");

return;

}

var url = 'userRegister/registerCheck.php?check=email';

$.post(

url,

'email=' + $('#email').val(),

function (data) {

switch (data.code) {

case 0:

$('#email').next().remove();

$('#email').after('').next().text(data.msg).css("color","green");

break;

case 1:

$('#email').next().remove();

$('#email').after('').next().text(data.msg).css("color","red");

break;

case 2:

$('#email').next().remove();

$('#email').after('').next().text(data.msg).css("color","red");

break;

}

}, 'json'

)

})

$('#password').blur(function () {

if ($('#email').val().length == 0) {

$('#email').next().remove();

$('#email').after('').next().text("邮箱不能为null");

return;

}

if ($('#password').val().length == 0) {

$('#password').next().remove();

$('#password').after('').next().text("密码不能为null");

return;

}

var url = 'userRegister/registerCheck.php?check=password';

$.post(

url,

'password=' + $('#password').val(),

function (data) {

switch (data.code) {

case 0:

$('#password').next().remove();

$('#password').after('').next().text(data.msg);

break;

case 1:

$('#password').next().remove();

$('#password').after('').next().text(data.msg);

break;

}

}, 'json'

)

})

$('#passwordSure').blur(function () {

if ($('#email').val().length == 0) {

$('#email').next().remove();

$('#email').after('').next().text("邮箱不能为null");

return;

}

if ($('#password').val().length == 0) {

$('#password').next().remove();

$('#password').after('').next().text("密码不能为null");

return;

}

if ($('#passwordSure').val().length == 0) {

$('#passwordSure').next().remove();

$('#passwordSure').after('').next().text("确认密码不能为null");

return;

}

var url = 'userRegister/registerCheck.php?check=passwordSure';

$.post(

url,

{

'password': $('#password').val(),

'passwordSure': $('#passwordSure').val()

},

function (data) {

switch (data.code) {

case 0:

$('#passwordSure').next().remove();

$('#passwordSure').after('').next().text(data.msg);

break;

case 1:

$('#passwordSure').next().remove();

$('#passwordSure').after('').next().text(data.msg);

break;

}

}, 'json'

)

})

$('#intro').blur(function () {

var url = 'userRegister/registerCheck.php?check=intro';

$.post(

url,

'intro=' + $('#intro').val(),

function (data) {

switch (data.code) {

case 0:

$('#intro').next().remove();

$('#intro').after('').next().text(data.msg);

break;

case 1:

$('#intro').next().remove();

$('#intro').after('').next().text(data.msg);

break;

case 2:

$('#intro').next().remove();

$('#intro').after('').next().text(data.msg);

break;

}

}, 'json'

)

})

//提交数据

$('#submit').click(function () {

var url = 'userRegister/registerCheck.php?check=submit';

$.post(url, $('#register').serialize(), function (data) {

// $('#submit').next().remove();

// $('#submit').after('').next().text(dataOut.msg +dataOut.data.password);

alert(data);

}, 'text')

})

})

运行实例 »

点击 "运行实例" 按钮查看在线实例

regiestCheck.php

/医院

* Created by PhpStorm.

* User: Administrator

* Date: 2018/4/17 0017

* Time: 上午 11:12

* 验证邮箱 密码 确认密码 等等 其他不用验证 有默认值 最后直接取出来就好了。

*/

header("content-type:text/html;charset=utf-8");

if (!empty($_GET['check'])) {

$check = $_GET['check'];

switch ($check) {

case 'email':

$email = $_POST['email'];

if (empty($_POST['email'])) {

exit(json_encode(['code' => 1, 'msg' => '邮箱不能为空']));

} else if (in_array($_POST['email'], array('admin@163.com', 'admin@qq.com'))) {

exit(json_encode(['code' => 2, 'msg' => '邮箱重复']));

} else {

exit(json_encode(['code' => 0, 'msg' => '可以注册']));

}

break;

case 'password':

$password = $_POST['password'];

if (empty($_POST['password'])) {

exit(json_encode(['code' => 1, 'msg' => '密码不能为空']));

} else {

exit(json_encode(['code' => 0, 'msg' => '密码通过']));

}

break;

case 'passwordSure':

$password = $_POST['password'];

$passwordSure = $_POST['passwordSure'];

if ($password == $passwordSure) {

exit(json_encode(['code' => 0, 'msg' => '密码通过']));

} else {

exit(json_encode(['code' => 0, 'msg' => '两次密码不一致']));

}

break;

case 'intro':

$intro = $_POST['intro'];

if (empty($intro)) {

exit(json_encode(['code' => 1, 'msg' => '简介不能为空']));

} else {

if (strlen($intro) 

exit(json_encode(['code' => 2, 'msg' => '简介长度不能<10']));

} else {

exit(json_encode(['code' => 0, 'msg' => '简介验证通过']));

}

}

break;

case 'submit':

//            echo $_POST['email'];

//            echo "
";

//            echo $_POST['password'];

//            echo "
";

//            echo $_POST['passwordSure'];

//            echo "
";

//            $sex = $_POST['sex'];

//            echo $sex;

//            echo "
";

//            $level = $_POST['level'];

//            echo $level;

//            echo "
";

//            $language = $_POST['language'];

//            var_dump($language);

exit(json_encode(['code' => 0, 'msg' => '注册成功了', 'data' => array($_POST['email'], $_POST['password'], $_POST['passwordSure'], $_POST['sex'], $_POST['level'], $_POST['language'])]));

break;

}

}

运行实例 »

点击 "运行实例" 按钮查看在线实例

cfe69c05a1653012df523f3982c34774.png

4f77eebcb39ac565f2114f3942d765af.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值