test.js
function c(){
var check_email = $("#u").val();
var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
flag = reg.test(check_email);
if(flag)
{var f = false;
var email_value = $('#u').val();
$.post("test1.php",{u:email_value,async:f},function(json){
//$('#res_mail').html(json);
if(json == "yes")
{
$('#cun').html("<font color='green' font-size='12'><b>此email可以注册!</b></font>");
$.data("tamp_email",true);
//$('#sub_reg').attr("disabled", false);
}else{
$('#cun').html("<font color='red' font-size='12'><b>此email已被注册!</b></font>");
$.data("tamp_email",false);
//$('#sub_reg').attr("disabled", true);
}
});
return tamp_email;
}
else{
$("#cun").html("<font color='red' font-size='12'><b>请输入正确的邮箱地址!</b></font>");
return false;
}
}
test1.php
<?php
include_once '../../sys/core/init.php';
$sql="SELECT * FROM user_register WHERE email ='$_POST'";
$q=$dbo->query($sql);if(count($q->fetchAll())>0){
echo "no";
}
else
{
echo "yes";}?>
判断格式时,显示提示信息,且当格式错误是能阻止提交。但是当判断用户名是否存在时,只能显示提示信息,却不能阻止提交。
function c(){
var check_email = $("#u").val();
var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
flag = reg.test(check_email);
if(flag)
{var f = false;
var email_value = $('#u').val();
$.post("test1.php",{u:email_value,async:f},function(json){
//$('#res_mail').html(json);
if(json == "yes")
{
$('#cun').html("<font color='green' font-size='12'><b>此email可以注册!</b></font>");
$.data("tamp_email",true);
//$('#sub_reg').attr("disabled", false);
}else{
$('#cun').html("<font color='red' font-size='12'><b>此email已被注册!</b></font>");
$.data("tamp_email",false);
//$('#sub_reg').attr("disabled", true);
}
});
return tamp_email;
}
else{
$("#cun").html("<font color='red' font-size='12'><b>请输入正确的邮箱地址!</b></font>");
return false;
}
}
test1.php
<?php
include_once '../../sys/core/init.php';
$sql="SELECT * FROM user_register WHERE email ='$_POST'";
$q=$dbo->query($sql);if(count($q->fetchAll())>0){
echo "no";
}
else
{
echo "yes";}?>
判断格式时,显示提示信息,且当格式错误是能阻止提交。但是当判断用户名是否存在时,只能显示提示信息,却不能阻止提交。
{
var email = $("#u").val();
var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
var flag = reg.test(email);
if(flag)
{
var tamp_email;//初始化,至于ajax得到结果后怎么处理那是你的事
$.ajax({
url: "test1.php",
type: "POST",
async: false,//同步
data: {u:email, async:false},
success: function(json){
//$('#res_mail').html(json);
if(json=="yes")
{
$('#cun').html("<font color='green' font-size='12'><b>此email可以注册!</b></font>");
$.data("tamp_email", true);
//$('#sub_reg').attr("disabled", false);
}
else
{
$('#cun').html("<font color='red' font-size='12'><b>此email已被注册!</b></font>");
$.data("tamp_email", false);
//$('#sub_reg').attr("disabled", true);
}
}
});
return tamp_email;
}
else
{
$("#cun").html("<font color='red' font-size='12'><b>请输入正确的邮箱地址!</b></font>");
return false;
}
}