/ Published in: JavaScript
                    
                                        
Javascript : Validate As You Type
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
//Javascript//
function validateAsYouType(inputElementId)
{
var val=inputElementId.value;
var lastLetter=val.substring((val.length-1),val.length);
if(isNaN(lastLetter))
{
//Input is OK. Let things be as they are.
}
else
{
//Input is not OK. Rmove the last entered character
var new_val=val.substr(0,val.length-1);
document.getElementById('inputtype').value=new_val;
}
}
//Javascript//
Sample usage:
<input type="text" value="" id="inputtype" onkeyup="return validateAsYouType(this);" />
Comments
 Subscribe to comments
                    Subscribe to comments
                
                