JavaScripTools Manual


Working with the DateMask

DateMask is a mask that recognizes and formats dates using a DateParser to instance. Several mask instances can (and should!) share a single parser.

The DateParser instance is passed on the constructor, as well as the control name or reference. As a shortcut, you can pass, instead of the parser, a string, containing the mask format. This will implicitly create a DateParser. But, when there are lots of controls being masked with the same format, it is better for all to share the same parser, so, you might want to create a DateParser previously and pass it to all masks. Sure this is a very small optimization, and you will probably notice no difference on fast computers...

Padding is very useful on the InputMask. If the mask is yyyy-MM-dd, for example, the user can type 5-1-9, and, when he leaves the field, the value will be 2005-01-09. For more details on padding, click here.

Examples (assuming controls called "myDate" and "myMonth"):

//Using the parser
var parser = new DateParser("yyyy-MM-dd");
new DateMask(parser, "myDate");

//Using a format string and event handlers
var mask = new DateMask("MM/yyyy", "myMonth");
mask.keyPressFunction = function(event, mask) {

Working with the NumberMask
Table of Contents Next:
Working with the SizeLimit