I have the following piece of code (which was given to me) to check a 'username' field 10 digits. The field must be exactly 10 digits to continue. It must have no letters or special characters in it -- just numbers. Can someone fix this snippet so that it works right? Currently, it is letting everything pass -- no matter if it's text, numbers, short, long... whatever. Here's the code:
function checkUsername() {
var exp = /^\d{10}$/;
if (entered.length(exp) >10 && entered.length(exp) <=9) {
alert("Username is not in the proper format. You are an idiot.");
return false;
}
return true;
}
||) not an "and" (&&). So maybe a little less with the idiot remarks. :)entered? Where is is declared?enteredis meant to be a global variable holding the username? Should be passed in as an argument. In any case, what isentered.length(regex)meant to do? That is gibberish.