I'm having a little issue with a masked input with jquery:
I have a phonenumber text input, so I masked it with a little plugin that I got from this site:
Masked-Input-Plugin by Digitalbrush
It's so usefull to mask inputs with non-complex rules, so I used this rule to mask my phonenumber input:
$("#txtHomePhoneNumber").mask("(99) 999-99 99");
Now the problem is when I want to let the user enter two type of phones on the same input, for example, the user can enter a phone number like this:
(02) 222 - 22 - 22
As well as:
(02) 222 - 22 - 2
Now, how should I concatenate this two rules, so that the masked input keeps formatting the input textbox (adding the dashes and parentheses)?
If you know another way or another plugin that could let me get what I want (even if it's without using this plugin), please let me know.
Thanks in advance.
First, include the jQuery and masked input javascript files. Next, call the mask function for those items you wish to have masked. jQuery(function($){ $("#date"). mask("99/99/9999"); $("#phone").
jQuery mask is a jQuery plugin that helps in putting on a mask on the basic HTML input fields and other elements. If the developer wants the input field to take inputs in a certain format only, then they can use the jQuery mask plugin for it.
The JavaScript Input Mask or masked textbox is a control that provides an easy and reliable way to collect user input based on a standard mask. It allows you to capture phone numbers, date values, credit card numbers, and other standard format values.
In computer programming, an input mask refers to a string expression, defined by a developer, that constrains user input. It can be said to be a template, or set format that entered data must conform to, ensuring data integrity by preventing transcription errors.
You can have the last character be optional. Put a question mark in the mask definition right before the character you want to start the optional input.
.mask("(99) 999-99-9?9")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With