This script will easily allow you to add an input mask to a textbox. The mask for a phone number could look like this for example “(###) ###-####”. Just give it a try to see it in action!
- Download the external JavaScript file
- Copy the coding into the HEAD of your HTML document
- Add the last code into the BODY of your HTML document
<!– STEP ONE: Download the external JavaScript file here: –>
http://javascriptsource.com/forms/dFilter.js
<!– STEP TWO: Paste this code into the HEAD of your HTML document –>
<HEAD>
<!– This script and many more are available free online at –>
<!– The JavaScript Source!! http://javascriptsource.com –>
<script type=’text/javascript’ src=’dFilter.js’></script>
</script>
</HEAD>
<!– STEP TWO: Copy this code into the BODY of your HTML document –>
<BODY>
<!– This script and many more are available free online at –>
<!– The JavaScript Source!! http://javascriptsource.com –>
<form name=”fred” action=”fred.htm” method=”post”>
<table>
<tr>
<td>SSN:</td>
<td><input value=”” type=”text” onKeyDown=”javascript:return dFilter (event.keyCode, this, ‘###-##-####’);” style=”font-family:verdana;font-size:10pt;width:110px;”></td>
</tr>
<tr>
<td>Phone:</td>
<td><input value=”” type=”text” onKeyDown=”javascript:return dFilter (event.keyCode, this, ‘(###) ###-####’);” style=”font-family:verdana;font-size:10pt;width:110px;”></td>
</tr>
<tr>
<td>Zip:</td>
<td><input value=”” type=”text” onKeyDown=”javascript:return dFilter (event.keyCode, this, ‘#####-####’);” style=”font-family:verdana;font-size:10pt;width:110px;”></td>
</tr>
</table>
</form>
<p><center>
<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>
by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>
</center><p>