The first field will only accept characters I have identified as appropriate for a person's name (alphabetical, space, hyphen, apostrophe, and period).
The second field will only accept letters.
The third field will only accept numbers.
The fourth field will only accept "name characters" and "numbers".
As you press down on each key on your keyboard, the keystroke is intercepted and only allows the value to be "accepted" if it matches the required criteria.
<form name="InputLimiter">
<p>Name Characters: <input type="text" id="NameCharacters" onkeypress="return inputLimiter(event,'NameCharacters')" value="Name" /></p>
<p>Letters Only: <input type="text" id="LettersOnly" onkeypress="return inputLimiter(event,'Letters')" value="LettersOnly" /></p>
<p>Numbers Only: <input type="text" id="NumbersOnly" onkeypress="return inputLimiter(event,'Numbers')" value="1234567890" /></p>
<p>Letters, Numbers, Hyphens, and Spaces: <input type="text" id="NameCharactersAndNumbers" onkeypress="return inputLimiter(event,'NameCharactersAndNumbers')" value="Letters Numbers Hyphens and Spaces" /></p>
</form>
<script type="text/javascript" language="javascript">
function inputLimiter(e,allow) {
var AllowableCharacters = '';
if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
if (allow == 'Numbers'){AllowableCharacters='1234567890';}
if (allow == 'NameCharacters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.\'';}
if (allow == 'NameCharactersAndNumbers'){AllowableCharacters='1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-\'';}
var k;
k=document.all?parseInt(e.keyCode): parseInt(e.which);
if (k!=13 && k!=8 && k!=0){
if ((e.ctrlKey==false) && (e.altKey==false)) {
return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
} else {
return true;
}
} else {
return true;
}
}
</script>