开发者

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

开发者 https://www.devze.com 2023-01-07 01:07 出处:网络
I have an input text element being used as a jQuery UI datepicker with a custom date format. The date format allows months to be entered in as JAN, FEB, etc and so the constrained input allows all cha

I have an input text element being used as a jQuery UI datepicker with a custom date format. The date format allows months to be entered in as JAN, FEB, etc and so the constrained input allows all characters to go through. See this question.

How can I restrict the t开发者_Go百科ext entered to match my date format "dd-M-yy"?

Is there a way to use jQuery to make the input text element behave like a masked edit text box?


I'd recommend using the jQuery MaskedInput plugin, assuming your input is fixed-width.


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?

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

you can specify the "constrainInput" option inside the datepicker its a boolean just set it to true. and avcorse sepcify your date format.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消