JavaScript Password verifier

Source: Internet
Author: User

JavaScript Tutorial Password Validator

The following check function, the password field is blank, only allow letters and numbers-this time no underscopes. Therefore, we should use a new regular expression to prohibit underscopes. These 1/[w_]/Only allow letters and numbers. Next, we want to allow at least 1 passwords to contain letters and numbers. To do this, we use the SEACRH () method and two regular expressions:/(Arizona, State) +/And/(0-9)/.

function ValidatePassword (FLD) {
var error = "";
var illegalchars =/[w_]/; Allow only letters and numbers

if (Fld.value = = "") {
Fld.style.background = ' yellow ';
Error = "You didn ' t enter a PASSWORD.N";
else if ((Fld.value.length < 7) | | (Fld.value.length > 15)) {
Error = "The password is the wrong length. n ";
Fld.style.background = ' yellow ';
else if (Illegalchars.test (Fld.value)) {
Error = "The password contains illegal CHARACTERS.N";
Fld.style.background = ' yellow ';
Or else if (! (Fld.value.search ((A-Z) +/)) && (Fld.value.search (/(0-9) +/))) {
Error = "The password must contain at least one NUMERAL.N";
Fld.style.background = ' yellow ';
} else {
Fld.style.background = ' white ';
}
return error;
}

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.