Multiple masks for phone numbers area code with 2 digits or 3 digits the rest is 7 digits
我有输入字段-电话号码,可以有2种格式的电话号码。
区号可以是2位或3位,其余数字为7位。
示例:
电话号码=" 0342356789";
我想将其屏蔽为以下格式:(00)000-0000
电话号码=" 052342356789";
我想将其屏蔽为以下格式:(000)000-0000
有人可以告诉我如何使用口罩吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <html> <head> <script src="https://code.jquery.com/jquery-3.4.1.min.js"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.1.62/jquery.inputmask.bundle.js"> </head> jQuery().ready(() => { var phones = [{"mask":"(##)###-####"}, {"mask":"(###)###-####"}]; jQuery('.phone').inputmask({ mask: phones, greedy: false, definitions: { '#': { validator:"[0-9]", cardinality: 1}} }); }); <body> <input type="text" class="phone" /> </body> </html> |