jQuery - 输入掩码插件
嘿,
有人知道 jquery 中的输入掩码吗?例如,一个字段必须包含三个字母,后跟 4 个数字。 CDA1234。如果在字段中写了一些与此不符的内容,则必须不断删除。
Hei
Have anyone idea of input mask in jquery For example a field must have three letters followed by 4 numbers. cda1234. If one writes something in the field that does not fit with this must be removed continuously.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 jQuery Mask 插件 (github.com/igorescobar/jQuery-Mask-Plugin) 上实现混合数字类型的掩码非常容易,
您将如下所示:
$('.your-field').mask('SSS0000')
一切就绪。该插件将处理无效输入和所有内容。
干杯,
伊戈尔.
Its very easy to implement masks with mixed digit types on jQuery Mask Plugin (github.com/igorescobar/jQuery-Mask-Plugin)
Your will look like this:
$('.your-field').mask('SSS0000')
And its all set. The plugin will take care of invalid input and everything.
Cheers,
Igor.
您好,这些链接应该为您提供有关如何实现此目标的构建博客。
首先,选择前 3 个字符,具体方法如下:
http://www.w3schools.com/jsref/jsref_substring.asp
然后检查是否它们是数字:
检查输入的数字是否是jquery中的数字
并且很快...
Hi there these links should give you the building blogs on how to achieve this.
First, select the first 3 charectors, here is how:
http://www.w3schools.com/jsref/jsref_substring.asp
then check if they are numbers:
checking if number entered is a digit in jquery
And so on...
制作了一个快速示例,请参阅: http://jsfiddle.net/g8KSg/2/
检查前 3 个字符为非整数,然后仅接受整数。
可以通过正则表达式变得更明智,但这应该给出一个起点:)
Cooked an fast example up, see: http://jsfiddle.net/g8KSg/2/
Checks for non integers for the first 3 characters, and then only accept integers.
Could proberbly be made wiser with regex, but this should give a starting point :)
您是否检查了 jQuery 的屏蔽输入插件
Did you check the Masked Input Plugin for jQuery