简体   繁体   English

如何使用jQuery限制输入到输入文本元素中的文本?

[英]How can I restrict the text entered into an input text element using jQuery?

I have an input text element being used as a jQuery UI datepicker with a custom date format. 我有一个输入文本元素用作具有自定义日期格式的jQuery UI日期选择器。 The date format allows months to be entered in as JAN, FEB, etc and so the constrained input allows all characters to go through. 日期格式允许以JAN,FEB等输入月份,因此受约束的输入允许所有字符通过。 See this question . 看到这个问题

How can I restrict the text entered to match my date format "dd-M-yy"? 如何限制输入的文本以匹配我的日期格式“dd-M-yy”?

Is there a way to use jQuery to make the input text element behave like a masked edit text box? 有没有办法使用jQuery使输入文本元素表现得像一个蒙版编辑文本框?

我建议使用jQuery MaskedInput插件 ,假设你的输入是固定宽度的。

It's a bit dirty, but maybe you can use http://www.zurb.com/playground/jquery-text-change-custom-event to create your own filter? 它有点脏,但也许您可以使用http://www.zurb.com/playground/jquery-text-change-custom-event来创建自己的过滤器?

The plugin isn't dirty mind you, it looks great, but it might be the wrong hammer for this nail. 插件对你来说并不脏,它看起来很棒,但对于这个指甲来说可能是错误的锤子。

if you are using a jquery date picker you have built in support for this allready inside the plugin 如果您使用的是jquery日期选择器,那么您已经在插件中内置了对此allready的支持

you can specify the "constrainInput" option inside the datepicker its a boolean just set it to true. 你可以在datepicker中指定“constrainInput”选项,它的布尔值只是将其设置为true。 and avcorse sepcify your date format. 和avcorse sepcify您的日期格式。

http://docs.jquery.com/UI/Datepicker#option-constrainInput http://docs.jquery.com/UI/Datepicker#option-constrainInput

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM