The output of this form is whenever you enter a wrong character, a warning will appear on the right side right after you onBlur. And when you enter the correct characters on the box and onBlur again, the warning will disappear.
The script is running okay except when you enter the valid characters and then you click outside the textbox, and then click again inside the textbox and input unwanted characters without deleting the previous valid characters you entered, the warning message doesn't appear.
Any suggestions how to make the warning message appear in this situation?
here's the code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function editThisOne(regThat,input,spanId,spanMessage)
{
if(!regThat.test(input))
{
if(spanId!=null)
while(spanId.firstChild)
spanId.removeChild(spanId.firstChild)
spanId.appendChild(document.createTextNode(spanMessage))
return false;
}
else
{
if(spanId!=null)
while(spanId.firstChild)
spanId.removeChild(spanId.firstChild)
return true;
}
}
function changeThis(wow,that)
{
return editThisOne(/[A-Za-z\.\'\-]{2,15}\s?[A-Za-z\.\'\-]{2,15}\s?[A-Za-z\.\'\-]{2,15}/,wow.value,that,"Please enter name correctly");
}
</script>
<div>
Enter your name:
<input id="name" onBlur="changeThis(this,document.getElementById('thisSpan'))">
<span id="thisSpan"></span>
</div>
</body>
</html>