I have these scripts...
Name: <input type="text" id="inputName" onblur="verifyName(this.value)">
<script type="text/javascript">
function verifyName(nameInput)
{
if(nameInput=="")
{
// error
alert('please enter your name');
}
else
{
// accepted
}
}
</script>
This will display an error if the user don't want to enter his/her name on the textbox.
What if the user is lazy and he/she will enter " " (a space or more) as a name? This can be accepted by the JavaScript. It will return false on the if
condition.
But I want the user not to enter only spaces. Is there any way to do that?
Note: Any number of spaces (without any letters) inputted are invalid.
If the user inputs one of the texts below, JavaScript should accepts/rejects the input as follows...
"John" --> valid
"" --> invalid
"John Doe" --> valid
" " --> invalid
"John Doe" --> valid (can be edited to remove too many spaces)
" Kim" --> valid (can be edited to remove too many spaces)
" " --> invalid