jquery Implementation user Information Modify validation Input method Rollup _jquery

Source: Internet
Author: User

This example describes the jquery implementation user Information modification validation input method. Share to everyone for your reference. as follows:

var realnameflag = 0;
var addressflag = 0;
var zipflag=0;
var cellphoneflag=0;
var homephoneflag=0;
var oldpasswordflag=1;
var newpasswordflag=1;
  Determine the email function check_email () {$ ("#showSpan"). Hide ();
  var email = $.trim ($ ("#email"). Val ());
    if (email = null | | | email = = "") {Emailflag = 1;
    $ ("#emailMsg"). HTML ("<span class= ' tips ' > Please enter your mailbox information </span>");
  Return //Determine if the input box is a mailbox format if (Email.replace (/[^\x00-\xff]/g, "* *"). Length <= 4 | | email.replace (/[^\X00-\XFF]/G, "* *"). Le
    Ngth >= {$ ("#emailMsg"). HTML ("<span class= ' tips ' > Mailbox length incorrect </span>");
    Emailflag = 1;
  return; } var reg =/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[
  \w-]+) +$/;
    if (reg.test (email)) {$ ("#emailMsg"). HTML ("");
    Emailflag = 0;
  return;
    else {$ (' #emailMsg '). HTML ("<span class= ' tips ' > Incorrect mailbox Format </span>");
    Emailflag = 1;
  return;
  The function Check_realname () {$ ("#showSpan"). Hide (); var realname = $.trim ($ ("#realname"). Val ()); Determines whether an empty if (Realname = null | | realname = = "") {$ ("#realnameMsg"). HTML ("<span class= ' tips ' > Please enter your real name, 20 English
    Text or 10 Chinese characters </span> ");
  Realnameflag = 1; else if (Realname.indexof ("• •")!=-1) {$ ("#realnameMsg"). HTML ("<span class= ' tips ' > Please enter your real name, 20 English or 10 Chinese characters <
    /SPAN> ");
    Realnameflag = 1;
  The name can not be added before and after · 
  else if (realname.substring (0, 1) = = "*" | | realname.substring (realname.length-1) = = "*")
    {Realnameflag = 1;
  $ ("#realnameMsg"). HTML ("<span class= ' tips ' > Please enter your real name, 20 English or 10 Chinese characters </span>"); else {var reg = new RegExp ("^" [a-za-z]|[
    \\u4E00-\\u9FFF]) +$ "," G "); 
      if (!reg.test (Realname)) {$ ("#realnameMsg"). HTML ("<span class= ' tips ' > Please enter your real name, 20 English or 10 Chinese characters </span>");
    Realnameflag = 1; else if (Realname.replace (/[^\x00-\xff]/g, "* *"). Length >= 4 && realname.replace (/[^\x00-\xff]/g, "* *")
      . length <= {realnameflag = 0; $ ("#realnameMsg"). HTML ("");
      else {realnameflag = 1;
    $ ("#realnameMsg"). HTML ("<span class= ' tips ' > Please enter your real name, 20 English or 10 Chinese characters </span>");
  }} function Check_cellphone () {$ ("#showSpan"). Hide ();
  var cellphone = $.trim ($ ("#cellphone"). Val ());
    while (true) {var start = cellphone.substring (0, 1);
    if (start = = "0") {cellphone = cellphone.substring (1);
    } else {break;
  } $ ("#cellphone"). Val (cellphone); if (cellphone = NULL | | cellphone = = "") {$ ("#cellphoneMsg"). HTML ("<span class= ' tips ' > Please enter mobile number </span>")
    ;
    Cellphoneflag = 1;
  Return var re =/^1{1}[3,4,5,8]{1}\d{9}$/;
    A regular expression that determines whether a number is (!re.test (cellphone)) {Cellphoneflag = 1;
    $ ("#cellphoneMsg"). HTML ("<span class= ' tips ' > Please enter the correct mobile phone number </span>");
  Return
    else {cellphoneflag = 0;
  $ ("#cellphoneMsg"). HTML ("");
  The function Check_homephone () {$ ("#showSpan"). Hide ();
  var homephone = $.trim ($ ("#homephone"). Val ()); if (hoMephone = = NULL | |
    HomePhone = = "") {homephoneflag=0;
    $ ("#homephoneMsg"). HTML ("");
  return; } var re=/(^ (\d{3,4}-)? \d{7,8}) $|
  (^1{1}[3,4,5,8]{1}\d{9}$)/;
    if (!re.test (HomePhone)) {homephoneflag=1;
    $ ("#homephoneMsg"). HTML ("<span class= ' tips ' > Please enter the phone number correctly in the format: 000-00000000</span>");
  return;
    }else {homephoneflag=0;
  $ ("#homephoneMsg"). HTML ("");
  The function check_address () {$ ("#showSpan"). Hide ();
  var address = $.trim ($ ("#address"). Val ()); To determine if NULL if (address = null | | = = = "") {$ ("#addressMsg"). HTML ("<span class= ' tips ' > Please enter the details </span&
    gt; ");
  Addressflag = 1;
    }else if (/[^\x00-\xff]/g, "* *"). Length > Address.replace) {addressflag = 1;
  $ ("#addressMsg"). HTML ("<span class= ' tips ' > length exceeding Long </span>");
    else {addressflag = 0;
  $ ("#addressMsg"). HTML ("");
  The function Check_zip () {$ ("#showSpan"). Hide ();
  var Zip=$.trim ($ ("#zip"). Val ());
  var re=/^[0-9]+$/; IfZip.length!= 0 && (!re.test (Zip) | | zip.length!= 6)) {zipflag=1;  
  $ ("#zipMsg"). HTML ("<span class= ' tips ' > Please enter ZIP Code, composed of 6 digits </span>");
    }else {zipflag=0;
  $ ("#zipMsg"). HTML ("");
  The function Check_oldpassword () {$ ("#msgSpan"). HTML ("");
  $ ("#newpsMsg"). HTML ("");
  $ ("#repsMsg"). HTML ("");
  var Oldps = $.trim ($ ("#oldPassword"). Val ());  
    if (Oldps = null | | oldps = = "") {Oldpasswordflag = 1;
    $ ("#oldpsMsg"). HTML ("<span class= ' tips ' > Please enter old password </span>");
    $ (this). focus ();
  return false; } var re=/^.
  {6,16}$/;  
    if (!re.test (Oldps)) {oldpasswordflag = 1;
    $ ("#oldpsMsg"). HTML ("<span class= ' tips ' > old password input length is incorrect </span>");
    $ (this). focus ();
  return false;  
    else {oldpasswordflag = 0;
  $ ("#oldpsMsg"). HTML ("");
  The function Check_newpassword () {$ ("#oldpsMsg"). HTML ("");
  $ ("#repsMsg"). HTML ("");
  $ ("#msgSpan"). HTML ("");
  $ ("#repeatPassword"). Val (""); var newps = $.trim ($ ("#newPassword "). Val ());  
    if (newps = null | | newps = = "") {newpasswordflag=1;
    $ ("#newpsMsg"). HTML ("<span class= ' tips ' > Please enter a new password, composed of 6-16-bit characters!</span>");
    $ (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 >) {new  
    Passwordflag = 1;
    $ ("#newpsMsg"). HTML ("<span class= ' tips ' > New password length is incorrect </span>");
    $ (this). focus ();
  return false;  
    } if (!re.test (newps)) {newpasswordflag = 1;
    $ ("#newpsMsg"). HTML ("<span class= ' tips ' > New password length is incorrect </span>");
    $ (this). focus ();
  return false;  
    }else {newpasswordflag = 0;
  $ ("#newpsMsg"). HTML ("");
  The function Check_repeatpassword () {$ ("#oldpsMsg"). HTML ("");
  $ ("#newpsMsg"). HTML ("");
  $ ("#msgSpan"). HTML (""); if ($ ("#repeatPassword"). Val () ==null | | $.trim ($ ("#repeatPassword"). val ()) = = $ ("#repsMsg"). HTML ("<span class= ' tips ' > Please enter duplicate new password </span>");
    $ (this). focus ();  
    Newpasswordflag = 1;
  return false;  
    }else if ($.trim ($ ("#repeatPassword"). Val ())!= $.trim ($ ("#newPassword"). Val ()) {newpasswordflag = 1;
    $ ("#repsMsg"). HTML ("<span class= ' tips ' > two times of inconsistent password input!</span>");
    $ (this). focus ();
  return false;  
    }else {newpasswordflag = 0;
  $ ("#repsMsg"). HTML ("");
  The function Check_cardnum () {$ ("#vcodeMsg"). HTML ("");
  $ ("#psMsg"). HTML ("");
  $ ("#strmsg"). Hide ();
  var cardnum = $.trim ($ ("#cardNum"). Val ());
    if (Cardnum = null | | cardnum = = "") {$ ("#numMsg"). HTML ("<span class= ' tips ' > Please enter card number </span>");
    Cardnumflag = 1;
  return false;
    }else {$ ("#numMsg"). HTML ("");
  cardnumflag=0;
  The function Check_password () {$ ("#vcodeMsg"). HTML ("");
  $ ("#numMsg"). HTML ("");
  $ ("#strmsg"). Hide ();
  var password = $.trim ($ ("#passWord"). Val ()); if (password = null | | password = = "") {PASSWORDFLAG = 1;
    $ ("#psMsg"). HTML ("<span class= ' tips ' > Please enter password </span>");
  return false;
    }else {passwordflag = 0;
  $ ("#psMsg"). HTML ("");
  The function Check_vcode () {$ ("#vcodeMsg"). HTML ("");
  $ ("#psMsg"). HTML ("");
  $ ("#numMsg"). HTML ("");
  $ ("#strmsg"). Hide ();
  var Vcode = $.trim ($ ("#vcode"). Val ()); 
    if (Vcode = null | | vcode = = "") {Vcodeflag = 1;
    $ ("#vcodeMsg"). HTML ("<span class= ' tips ' > Please enter validation code </span>");
  return false;
  } var re=/^[0-9]*$/; 
    if (!re.test (Vcode)) {vcodeflag = 1;
    $ ("#vcodeMsg"). HTML ("<span class= ' tips ' > Please enter the validation code correctly </span>");
  return false; 
     }else {vcodeflag = 0;
   $ ("#vcodeMsg"). HTML (""); } $ (document). Ready (function () {/*** Modify user information authentication Begini//Begin Email $ ("#email"). focus (function () {check_email ();}
);
The mailbox format is judged $ ("#email"). blur (function () {check_email ();});
End Email//bengin realname $ (' #realname '). focus (function () {check_realname ();}); Verify that the realname is correct $ ("#realnamE "). blur (function () {check_realname ();});  End Realname//bengin Cellphone $ (' #cellphone '). focus (function () {check_cellphone ();
});
Cell phone number format to determine $ ("#cellphone"). blur (function () {Check_cellphone ();});  End cellphone//bengin homephone $ (' #homephone '). focus (function () {check_homephone ();
});
$ ("#homephone"). blur (function () {Check_homephone ();});  End HomePhone//bengin Addr//Verify that the address is correct $ ("#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//Get city Level $ ("#province"). Change (function () {var province=$ (this). Val ();
    $.post ("_jquery", {"type": "Getprovince", province:province}, Function (msg) {$ ("#city"). HTML (msg);        
  $ ("#region"). HTML ("");
});
});
  Get County $ ("#city"). Change (function () {var city=$ (this). Val (); $.post ("_jquery", {"type": "Getcity", city:city}, Function (msg) {$ ("#regIon "). HTML (msg);
});
}); /*** Modify user information authentication end ***********//***------Password modification validation begin *************///begin $ ("#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 ();});
/***------Password Modification verification End *************//****---------Card query form submit validation 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 ();
});
  /****---------Card Query form Submit Verify end ***********///user order cancellation, $ ("#cancelreason"). focus (function () {$ ("#errorinfo"). HTML ("");
$ ("#errorinfo"). Removeclass ("Tips");

}); 
 $ ("#cancelreason"). Bind (' input PropertyChange ', function () {var maxLength = 65; if ($ (this). Val (). length > MaxLength) {$ (a). Val ($ (this). Val (). substring (0, MaxLength));
return false;
})
//-----

});
  End Ready//Modify user Information Form Submit 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 ("Please select Gender");
    $ ("#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 ("<span class= tips ' > Please select Region </span>");
  return;
    } if (addressflag!= 0 | | $ ("#address"). val () = NULL | | $ ("#address"). val () = "") {$ ("#address"). focus ();
  return;
    } if (Zipflag!= 0) {$ ("#zip"). focus ();
  return;
$ ("#myform"). Submit ();
  ///Modify user Information Form reset 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 ());
  ///Modify password submit 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 ();
  //Get Validation code 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. FadeIn (' slow ');
}); } function Removefavorite (GOODSID) {if confirm (' OK to delete the product?
  ") {document.location.href="/myremovefavorite.html?goodsid= "+GOODSID;
  } function Selectprovince (value) {//Export province city information. $.post ("_jquery", {"type": "Getprovince", Province:value}, funCtion (data) {$ ("#city"). HTML (data);      
  $ ("#region"). HTML ("");
});
  function Selectcity (value) {//Export town town information.        
  $.post ("_jquery", {"type": "Getcity", City:value}, function (data) {$ ("#region"). HTML (data);
});

 }

I hope this article will help you with your jquery programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.