I figure, given a week and Red Bull, I could make something that does this, but first, I wanted to find out if it had been done already.
I know input masks already exist: For example, __/__/____
. So you can just type a date, and voila, 12/31/2010
.
However, if I were to go in and realize I meant to put开发者_开发知识库 December 20th, I go to the 3 in 31, hit delete once, and now it displays 12/12/010_
. That's not very helpful. It's because the internal value is still simply "12312010", so when you delete '3' it becomes "1212010", and that is inserted into the mask accordingly.
Is there any existing JavaScript mask that will enforce blocks? So that, if I did what I described above, it would then display 12/1_/2010
? I don't mind if it still submits as "1212010", as long as it displays properly.
Would prefer a jQuery plugin, but straight JavaScript works.
Look into regular expressions. JavaScript has excellent support for it.
Here are some options:
- ) Seperate Fields: http://jsfiddle.net/Zhb8x/
- ) On change only mask: http://jsfiddle.net/WzYDv/1/ The user would have to hit enter or leave focus and the mask would apply.
- ) KeyPress and Change: http://jsfiddle.net/WzYDv/
imask does exactly what you want
精彩评论