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;
}