Say when its phone number, instead of validation after submit we can restrict users to enter non numeric characters using the following script:
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if(!((charCode>=48&&charCode<=57)|| (charCode==46) || (charCode==8))) return false; return true; } To use it in HTML: <input type="text" onkeypress="return isNumberKey(event);" />