JS Script Input Control Summary

Source: Internet
Author: User

1. Detection user name can only be made up of Chinese and English, numbers and underscores, can not use other symbols, the user name is already exist

function Checkloginaccount () {
var msg = ';
var nameid1 = document.getElementById ("login_name"). Value;
if (Nameid1.length < 4 | | nameid1.length > 20) {
msg = "User name length can only be between 4-20-bit characters";
Alert (msg);
return false;
}
else {
for (var index = 0; index < nameid1.length; index++) {
c = Nameid1.charat (index);
c = C.touppercase ();
if (! ( (c >= "A" && C <= "Z") | | (c >= "0" && C <= "9") | | c = = "_" | | c>= "\u4e00" &&c<= "\u9fa5") {
msg = "User name can only be made up of Chinese, English, numerals and underscores, cannot use other symbols";
Alert (msg);
return false;
}
}
}
var params = {loginName: $ (' #login_name '). Val ()};
$.post ("Userregistercheckloginname", params, function (data) {//user name already exists
if (Data.result = = "Error") {
RetVal = false;
msg = "The account already exists, please modify";
Alert (msg);
document.getElementById ("Regnamehint"). InnerHTML = msg;//This sentence is displayed somewhere in the page, usually after the detection input box, but to define DIV or other, id//For Regnamehi Nt
} else if (Data.result = = "Success") {
RetVal = true;
}
}, "JSON");
R Eturn RetVal;
}

2. Detect the password entered two times the password is consistent, whether it conforms to the specifications

function Checkpassword () {
var userpwd = document.getElementById ("pwd"). Value;
var pwdrepeat = document.getElementById ("Rpwd"). Value;
if (Userpwd.length < 6 | | userpwd.length > 20)
{
msg = "Password length 6-20 characters, please re-enter";
Alert (msg);
return false;
} else {
if (userpwd!== pwdrepeat) {
msg = "does not match the password entered for the first time!" ";
Alert (msg);
return false;
}
else {
return true;
}
}
}

3. Check whether the input mobile phone number meets the requirements

function Checkphone () {
var link_phone = document.getElementById ("Link_phone"). Value;
if (link_phone.length! = 11) {
msg = "Cell phone number format is not correct, please re-enter";
Alert (msg);
return false;
}
for (var index = 0; index < link_phone.length; index++) {
c = Link_phone.charat (index);
if (! ( C >= "0" && C <= "9")) {
msg = "Cell phone number format is not correct, please re-enter";
Alert (msg);
return false;
}
}

return true;
}

Note: You need to introduce <script src= "Xx/jquery.js" type= "Text/javascript" ></script>//xx as a relative path before use

JS Script Input Control Summary

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.