Input Mask | JavaScriptSource

Input Mask

Baron Schwartz Aug 10, 2007


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.)

Date (US format):
Phone number:


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


Paste this code into the HEAD section of your HTML document.


Paste this code into the BODY section of your HTML document

Leave a Response


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})?$/

Ken Whittington Nov 20, 2008

thanks, and I have used it for bank account input-mask.

kiokuw Oct 19, 2008

You will need to submit your question to the [a href=""]JavaScript forums[/a].

Lee May 12, 2008

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

Mike Guarino May 8, 2008

Yes, it doesn't work in IE.

Lee Sep 5, 2007