Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  139] [ 1]  / answers: 1 / hits: 23373  / 11 Years ago, tue, march 12, 2013, 12:00:00

Im using jquery masked input plugin and need to have a phone field with the following format:



1 (222) - 000 - 1114


my code looks like this:



$(#myPhone).mask(9 (999) - 999 - 9999);


now i cant seem to get it to work to make the first digit optional but the rest mandatory. So the following numbers are valid:



1 (222) - 000 - 1114
(222) - 000 - 1114


and the following numbers are invalid



1 (222) - 000 - 11
(222) - 00 - 0011


using ?9 (999) - 999- 9999 will not work since it makes the whole thing optional



If this cant be done in masked can someone help me out with regular expression to achieve this?


More From » jquery

 Answers
561

Try this:



$.mask.definitions['~'] = '([0-9] )?';
$(#myPhone).mask(~(999) - 999 - 9999);

[#79631] Monday, March 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
averyc

Total Points: 102
Total Questions: 113
Total Answers: 89

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;