强制执行部分的 Javascript 输入掩码?
我想,给定一周的时间和红牛,我可以做一些做到这一点的东西,但首先,我想知道它是否已经完成了。
我知道输入掩码已经存在:例如,__/__/____
。因此,您只需输入日期即可,瞧,12/31/2010
。
但是,如果我进入并意识到我要输入 12 月 20 日,我会转到 31 中的 3,点击删除一次,现在它会显示 12/12/010_
。这不是很有帮助。这是因为内部值仍然只是“12312010”,所以当您删除“3”时,它会变成“1212010”,并且相应地插入到掩码中。
是否有任何现有的 JavaScript 掩码可以强制执行阻止?那么,如果我执行上述操作,它就会显示 12/1_/2010
?我不介意它是否仍以“1212010”提交,只要它能正确显示即可。
更喜欢 jQuery 插件,但直接使用 JavaScript 就可以了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看正则表达式。 JavaScript 对其有很好的支持。
Look into regular expressions. JavaScript has excellent support for it.
以下是一些选项:
Here are some options:
imask 正是您想要的
imask does exactly what you want