A simple and quick way to add masks to form fields is to use a jQuery plugin, this plugin is called Masked Input Plugin.
To create a mask, you just need to provide a simple javascript command, with only the following rules:
- a – Represents an alphabetic character (A-Z, a-z)
- 9 – Represents a numeric character (0-9)
- * – Represents an alphanumeric character (A-Z, a-z ,0-9)
Let’s look at some practical examples:
Note: we’re using the jQuery selector through the ID attribute.
Mask for a Telephone field:
| |
Mask for an RG field:
| |
Mask for a CPF field:
| |
Mask for a Date field:
| |
Mask for a Time field:
| |
Mask for a Postal code field:
| |