Making a basic validation script, i hit a snag.
If user was to input say " "(minus quotes), into the textfield and then submit it the length check i have used would return it as true and therefore execute the rest of the code.
Is there a way to compensate for spaces, as to include them in the length?
Or do you have a different idea?
The code:
[code=javascript]
function validateInput()
{
var username = document.sign_u p.username
var password = document.sign_u p.password
var email = document.sign_u p.email
var secondary_email = document.sign_u p.secondary_ema il
if(username.len gth <= 6 || username.value == ""){ //check for length
alert("Username must be longer than 6 characters!\n\n- mahcuz")
}
else if(username.len gth >= 14){ //check for length
alert("Username must be shorter than 14 characters!\n\n- mahcuz")
}
else{
document.sign_u p.submit()
}
}
[/code]
If user was to input say " "(minus quotes), into the textfield and then submit it the length check i have used would return it as true and therefore execute the rest of the code.
Is there a way to compensate for spaces, as to include them in the length?
Or do you have a different idea?
The code:
[code=javascript]
function validateInput()
{
var username = document.sign_u p.username
var password = document.sign_u p.password
var email = document.sign_u p.email
var secondary_email = document.sign_u p.secondary_ema il
if(username.len gth <= 6 || username.value == ""){ //check for length
alert("Username must be longer than 6 characters!\n\n- mahcuz")
}
else if(username.len gth >= 14){ //check for length
alert("Username must be shorter than 14 characters!\n\n- mahcuz")
}
else{
document.sign_u p.submit()
}
}
[/code]
Comment