JavaScript User name Validation

Source: Internet
Author: User

JavaScript Tutorial User Name Verification
The following check function if the user enters any user name in all fields. If it is not empty, we check the length of the string and allow a unique username of 5 to 15 characters. Next, we use JavaScript regular expressions/tiles/disallow the illegal characters that appear in the user name. We want to allow only letters, numbers and underscopes.

function Validateusername (FLD) {
var error = "";
var illegalchars =/w/; Allow letters, numbers, and underscores

if (Fld.value = = "") {
Fld.style.background = ' yellow ';
Error = "You didn ' t enter a USERNAME.N";
else if ((Fld.value.length < 5) | | (Fld.value.length > 15)) {
Fld.style.background = ' yellow ';
Error = "The username is the wrong LENGTH.N";
else if (Illegalchars.test (Fld.value)) {
Fld.style.background = ' yellow ';
Error = "The username contains illegal CHARACTERS.N";
} else {
Fld.style.background = ' white ';
}
return error;
}

Related Article

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.