码迷,mamicode.com
首页 > 其他好文 > 详细

ajax验证输入格式是否正确

时间:2014-05-17 18:11:12      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:style   c   ext   http   int   a   

var user = $("user");
var from1 = $("from1");
var userCheck = $("userCheck");
var reg = /^[a-zA-Z][a-zA-Z0-9]{5,15}$/;
var pwdyi =$("pwdyi");
var pawcheck = $("userPwd");
var pwd =$("pwd");
var userPwder =$("userPwder");
function checkUser(){
if(user.value == null || user.value.length == 0){
userCheck.innerHTML = "用户名不能为空";
}
else if(user.value.length < 6){
userCheck.innerHTML = "用户名不能小于6位";
}
else if(!reg.test(user.value)){
userCheck.innerHTML = "用户名必须以字母开头,字母数字结尾,最长不能超过16位";
}
else{
userCheck.innerHTML = "";

// userCheck.innerHTML = "用户名正确";
}
}
function checkpwd(){
if(pwdyi.value == null || pwdyi.value.length == 0){
pawcheck.innerHTML = "密码不能为空";
}
if(pwdyi.value.length <= 6){
pawcheck.innerHTML = "用户名密码不能小于6位";
}
else{
pawcheck.innerHTML = " ";
// checkHaveUser(pwdyi.value);
// userCheck.innerHTML = "用户名正确";
}
}
function checkpwder(){
if(pwdyi.value == pwd.value){
userPwder.style.display = "none";
}
else{
userPwder.innerHTML= "输入的密码不一致";
}
}
var xmlHttp;
function getXmlHttp(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("MICROSOFT.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}

function checkHaveUser(obj){
getXmlHttp();
xmlHttp.open("GET","checkUser.php?userName="+obj,true);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var str = parseInt(xmlHttp.responseText);
if(str > 0){
userCheck.innerHTML = "用户已经存在,请选择其他用户名";
}else{
userCheck.innerHTML = "可以注册";
}
}
}
}
xmlHttp.send(null);
}
function checkYZM(){


getXmlHttp();
var f = false;
xmlHttp.open("GET","checkYZM.php?yzm="+yzm.value,false);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var str = parseInt(xmlHttp.responseText);
if(str){
yzmCheck.innerHTML = "验证成功!";
f = true;
}else{
yzmCheck.innerHTML = "验证失败!";
f = false;
}
}
}
}
xmlHttp.send(null);
return f;

}

function $(id){
return document.getElementById(id);
}

function submit1(){
document.forms[‘from1‘].submit();
}

ajax验证输入格式是否正确,布布扣,bubuko.com

ajax验证输入格式是否正确

标签:style   c   ext   http   int   a   

原文地址:http://www.cnblogs.com/wanger1994/p/3732558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!