Auto-format structured data (phone, date) using jQuery plugin (or failing that vanilla JavaScript)

2021/01/31 06:41 · jquery ·  · 0评论

I like jQuery and I was wondering if anyone have used a good plugin or (non-jQuery) JavaScript library that allows for auto-formatting of structured fields like phone numbers or dates. I know of the jquery-ui-datapicker plugin, and not what I am looking for here. You may type in a phone number as 123 which then becomes (123), additional numbers will be formatted as (123) 456 7890 Ext. 123456. If you press delete the auto-formatting stuff disappears automatically, and repositioning of the cursor, say, after (123) and pressing delete will remove the 3 and make the rest (124) 567 8901 Ext. 23456. The ones that I have played with appears unreliable.

Does the Masked Input plugin do what you need or that one you have already found to be unreliable?

Allan,

I do believe your best bet would be to use regular expressions inside of two separate formatting methods in order to achieve the desired results. This will be rather straight forward for phone numbers and I'll post a code example if one isn't posted by the time I sit back and have 10 minutes straight to write something up. Perhaps for the date field, you can use something like the jQuery UI Datepicker instead? http://marcgrabanski.com/pages/code/jquery-ui-datepicker

HTH,

/sf

本文地址:http://jquery.askforanswer.com/auto-format-structured-data-phone-date-using-jquery-plugin-or-failing-that-vanilla-javascript.html
文章标签: ,   ,   ,  
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!

文件下载

老薛主机终身7折优惠码boke112

上一篇:
下一篇:

评论已关闭!