Input Mask
General
This script uses unobtrusive JavaScript to implement "input masks." The maximum field length is automatically limited to the length of the mask. The characters that are entered into the fields are constrained, and separators are automatically added. (No actual validation is done. Check our site for validation scripts.)
Notes
- Created by: Baron Schwartz
- Web Site: http://www.xaprb.com/
- Posted: August 10, 2007
Requires the Prototype JavaScript framework, available at the Prototype Web site.
Source Code
Paste this source code into the designated areas.
External file
Paste this code into an external JavaScript file named: html-form-input-mask.js
Head
Paste this code into the HEAD section of your HTML document.
Body
Paste this code into the BODY section of your HTML document


Leave a Response
(12 comments)I can't seem to get this code to work with the regex for money I've been trying from different sites.[br /][br /]Is there something special I need to do? Here are a few I've tried:[br /][br /]regex: /[0-9]+(,[0-9]{3})*(\.[0-9]{2})?$/[br /]regex: /[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{2})?[br /]regex: /(((\d{1,3},)+\d{3})|\d+)\.\d{2}/[br /]regex: /^(0|[1-9]\d{0,2}(,?\d{3})*)(\.\d{1,2})?$/
thanks, and I have used it for bank account input-mask.
You will need to submit your question to the [a href="http://www.webdeveloper.com/forum/forumdisplay.php?f=3"]JavaScript forums[/a].
I am having trouble with the header code: The function is not recognized as a function and prototype.js does not exist. I am using Visual Studio 2005 ASP.NET running in IE
Yes, it doesn't work in IE.