when I enter the name it will show "right symbol" beside the text-box. can you tel me it coding...may I do this type of validation using javascript
Yes you can do this type of validation in Javascript. In fact one of the primary uses for Javascript was to do form validation. There are multiple ways to do it and there are even libraries and frameworks (example) to do the form validation.
This is so common that some browsers have built-in validation algorithms (for example if <input type="email">
complains if the contents of it doesn't look like an email address in latest Google Chrome).
If you want to do the validation, there are a couple of events that might be of your interest. onblur
happens when the form element loses control. onkeypress
happens as soon as user presses a key. There are other events as well. But usually you want to do the validation when user changes focus from the control to another one (onblur
).
<!DOCTYPE html>
<html>
<head>
</head>
<body>
Enter name then press tab or click outside the input field:
<input type="text" name="fname" id="fname" onblur="validate()"/>
</body>
</html>
And the validate()
function can be something like this:
function validate()
{
var val = document.getElementById("fname").value
if ( /\d/.test( val ) ) {
alert( "First name cannot have digits in it: " + val );
}
}
You can search the net for more info.