本文实例讲述了jquery实现用户信息修改验证输入方法。分享给大家供大家参考。具体如下:
$("#msgSpan").html("");
$("#newpsMsg").html("");
$("#repsMsg").html("");
var oldPS = $.trim($("#oldPassword").val());
if(oldPS == null || oldPS == "")
{
oldpasswordFlag = 1;
$("#oldpsMsg").html("请输入旧密码");
$(this).focus();
return false;
}
var re=/^.{6,16}$/;
if(!re.test(oldPS))
{
oldpasswordFlag = 1;
$("#oldpsMsg").html("旧密码输入长度不正确");
$(this).focus();
return false;
}
else
{
oldpasswordFlag = 0;
$("#oldpsMsg").html("");
}
}
function checknewPassword()
{
$("#oldpsMsg").html("");
$("#repsMsg").html("");
$("#msgSpan").html("");
$("#repeatPassword").val("");
var newPS = $.trim($("#newPassword").val());
if(newPS == null || newPS == "")
{
newpasswordFlag=1;
$("#newpsMsg").html("请输入新密码,由6-16位字符组成!");
$(this).focus();
return false;
}
//var re=/^[A-Za-z0-9-]{6,16}$/;
var re=/^.{6,16}$/;
if (newPS.replace(/[^\x00-\xff]/g,"").length <6 || newPS.replace(/[^\x00-\xff]/g,"").length > 16)
{
newpasswordFlag = 1;
$("#newpsMsg").html("新密码长度不正确");
$(this).focus();
return false;
}
if(!re.test(newPS))
{
newpasswordFlag = 1;
$("#newpsMsg").html("新密码长度不正确");
$(this).focus();
return false;
}else
{
newpasswordFlag = 0;
$("#newpsMsg").html("");
}
}
function check_repeatPassword()
{
$("#oldpsMsg").html("");
$("#newpsMsg").html("");
$("#msgSpan").html("");
if( $("#repeatPassword").val()==null || $.trim($("#repeatPassword").val()) =="")
{
$("#repsMsg").html("请输入重复新密码");
$(this).focus();
newpasswordFlag = 1;
return false;
}else
if ( $.trim($("#repeatPassword").val()) != $.trim($("#newPassword").val()))
{
newpasswordFlag = 1;
$("#repsMsg").html("两次密码输入的不一致!");
$(this).focus();
return false;
}else
{
newpasswordFlag = 0;
$("#repsMsg").html("");
}
}
function check_cardNum()
{
$("#vcodeMsg").html("");
$("#psMsg").html("");
$("#strmsg").hide();
var cardnum = $.trim( $("#cardNum").val());
if(cardnum == null || cardnum == "")
{
$("#numMsg").html("请输入卡号");
cardnumFlag = 1;
return false;
}else
{
$("#numMsg").html("");
cardnumFlag=0;
}
}
function check_passWord()
{
$("#vcodeMsg").html("");
$("#numMsg").html("");
$("#strmsg").hide();
var password = $.trim( $("#passWord").val());
if(password == null || password == "" )
{
passwordFlag = 1;
$("#psMsg").html("请输入密码");
return false;
}else
{
passwordFlag = 0;
$("#psMsg").html("");
}
}
function check_vcode()
{
$("#vcodeMsg").html("");
$("#psMsg").html("");
$("#numMsg").html("");
$("#strmsg").hide();
var vcode = $.trim( $("#vcode").val());
if(vcode == null || vcode =="")
{
vcodeFlag = 1;
$("#vcodeMsg").html("请输入验证码");
return false;
}
var re= /^[0-9]*$/;
if(!re.test(vcode))
{
vcodeFlag = 1;
$("#vcodeMsg").html("请正确输入验证码");
return false;
}else
{
vcodeFlag = 0;
$("#vcodeMsg").html("");
}
}
$(document).ready(function()
{
/** 修改用户信息验证 begini /
// begin email
$("#email").focus(function() { check_email();});
// 邮箱格式判断
$("#email").blur(function(){check_email();});
//end email
//bengin realname
$("#realname").focus(function() {check_realname();});
// 校验realname是否正确
$("#realname").blur(function() {check_realname();});
//end realname
//bengin cellphone
$("#cellphone").focus(function() { check_cellphone(); });
// 手机号码格式判断
$("#cellphone").blur(function() { check_cellphone(); });
//end cellphone
//bengin homephone
$("#homephone").focus(function(){ check_homephone(); });
$("#homephone").blur(function(){ check_homephone();});
//end homephone
//bengin addr
// 校验address是否正确
$("#address").focus(function(){ check_address(); });
$("#address").blur(function() { check_address();});
//end addr
//bengin zip
$("#zip").focus(function(){ check_zip(); });
$("#zip").blur(function(){ check_zip(); });
//end zip
//获取市级
$("#province").change(function(){
var province=$(this).val();
$.post("_jquery",{"type":"getProvince",province:province},function(msg){
$("#city").html(msg);
$("#region").html("");
});
});
//获取县级
$("#city").change(function(){
var city=$(this).val();
$.post("_jquery",{"type":"getCity",city:city},function(msg){
$("#region").html(msg);
});
});
/* 修改用户信息验证 end *****/
/*------密码修改验证 begin ***/
//begin oldpassword
$("#oldPassword").focus(function(){ check_oldPassword();});
$("#oldPassword").blur(function(){ check_oldPassword();});
//end oldpassword
//begin newpassword
$("#newPassword").focus(function(){ check_newPassword();});
//newpassword
$("#newPassword").blur(function(){ check_newPassword();});
// repeatpassword
$("#repeatPassword").focus(function(){ check_repeatPassword();});
$("#repeatPassword").blur(function(){ check_repeatPassword();});
/*------密码修改验证 end ***/
/** ---------卡查询表单提交验证 begin *****/
var cardnumFlag = 0;
var passwordFlag = 0;
var vcodeFlag = 0;
$("#cardNum").focus(function(){ check_cardNum();});
$("#cardNum").blur(function(){ check_cardNum();});
$("#passWord").focus(function(){ check_passWord();});
$("#passWord").blur(function(){ check_passWord();});
$("#vcode").focus(function(){ check_vcode(); });
$("#vcode").blur(function(){ check_vcode(); });
$("#formsubmit").click(function(){
$("#strmsg").hide();
$("#numMsg").html("");
$("#psMsg").html("");
$("#vcodeMsg").html("");
var re= /^[0-9]*$/;
if(cardnumFlag != 0 || $.trim($("#cardNum").val()) == "" || $("#cardNum").val() == null )
{
$("#cardNum").focus();
return ;
}
if(passwordFlag != 0 || $.trim($("#passWord").val()) == "" || $("#passWord").val() == null)
{
$("#passWord").focus();
return ;
}
if(($("#vcode").val() != "" && !re.test($("#vcode").val())) || vcodeFlag != 0 || $("#vcode").val() == "" )
{
$("#vcode").focus();
return ;
}
$("#cardform").submit();
});
/** ---------卡查询表单提交验证 end *****/
//用户订单取消,
$("#cancelreason").focus(function(){
$("#errorinfo").html("");
$("#errorinfo").removeClass("tips");
});
$("#cancelreason").bind('input propertychange',function() {
var maxLength = 65;
if ($(this).val().length > maxLength) {
$(this).val($(this).val().substring(0,maxLength));
}
return false;
})
//-----
});
//end ready
//修改用户信息表单提交
function formsubmit()
{
$("#showSpan").hide();
var province=$("#province").val();
var city=$("#city").val();
var region=$("#region").val();
$("#emailMsg").html("");
$("#realnameMsg").html("");
$("#cellphoneMsg").html("");
$("#homephoneMsg").html("");
$("#szcode").html("");
$("#addressMsg").html("");
$("#zipMsg").html("");
if(emailFlag != 0 || $("#email").val()== null || $("#email").val()== "")
{
$("#email").focus();
return ;
}
if(realnameFlag != 0 || $("#realname").val()== null || $("#realname").val()== "")
{
$("#realname").focus();
return ;
}
if($("input[name=sex]:checked").val()==null||$("input[name=sex]:checked").val()==""){
alert("请选择性别");
$("#sex").focus();
return;
}
if(cellphoneFlag != 0)
{
$("#cellphone").focus();
return ;
}
if(homephoneFlag != 0)
{
$("#homephone").focus();
return ;
}
if( province == "" || city == "" || region== "" || province == null || city == null || region== null)
{
$("#szcode").html("请选择地区");
return ;
}
if(addressFlag != 0 || $("#address").val() == null || $("#address").val() == "")
{
$("#address").focus();
return ;
}
if(zipFlag != 0)
{
$("#zip").focus();
return ;
}
$("#myform").submit();
}
//修改用户信息表单重置
function formreset()
{
$("#showSpan").hide();
document.forms["myform"].reset();
$("#emailMsg").html("");
$("#realnameMsg").html("");
$("#cellphoneMsg").html("");
$("#homephoneMsg").html("");
$("#addressMsg").html("");
$("#zipMsg").html("");
$("#szcode").html("");
$("#province").html($("#hprovince").val());
$("#city").html($("#hcity").val());
$("#region").html($("#hregion").val());
}
//修改密码提交form
function psformSubmit()
{
$("#oldpsMsg").html("");;
$("#newpsMsg").html("");
$("#repsMsg").html("");
var oldps = $.trim($("#oldPassword").val());
var newps = $.trim( $("#newPassword").val());
var reps = $.trim($("#repeatPassword").val());
if( oldpasswordFlag != 0 || oldps =="" || oldps ==null )
{
$("#oldPassword").focus();
return ;
}
if(newpasswordFlag != 0 || newps =="" || newps ==null )
{
$("#newPassword").focus();
return ;
}
if( newpasswordFlag != 0 || reps == null || reps =="" || reps != newps)
{
$("#repeatPassword").focus();
return ;
}
$("#psform").submit();
}
//获取验证码
function dochange()
{
///$("#vcodeImg").attr("src","_verifycode?" + new Date());
var imgObj="#vcodeImg";
$(imgObj).fadeOut('fast',function(){
var datenow = new Date();
$(this).attr('src','_verifycode?ver=' + datenow.getMilliseconds()).delay(200).fadeIn('slow');
});
}
function removefavorite(goodsid)
{
if(confirm('确定删除商品吗?'))
{
document.location.href="/myremovefavorite.html?goodsid="+goodsid;
}
}
function selectProvince(value)
{ //导出省份下市区 信息。
$.post("_jquery",province:value},function(data){
$("#city").html(data);
$("#region").html("");
});
}
function selectCity(value)
{ //导出市区 下县城信息。
$.post("_jquery",city:value},function(data){
$("#region").html(data);
});
}
希望本文所述对大家的jquery程序设计有所帮助。
原文链接:https://www.f2er.com/jquery/53356.html