how can we date mask a text field using javascriptjQuery? - Stack Overflow

I am having a text field for date. Now i would like to mask this text field so that a user can input on

I am having a text field for date. Now i would like to mask this text field so that a user can input only date value. I even found a jQuery plugin for this. But that doesn't seems to help, as you can input 22/22/2222 in the field that too is accepted by this plugin, which is obviously not a valid date. What is the possible solution?

I am having a text field for date. Now i would like to mask this text field so that a user can input only date value. I even found a jQuery plugin for this. But that doesn't seems to help, as you can input 22/22/2222 in the field that too is accepted by this plugin, which is obviously not a valid date. What is the possible solution?

Share Improve this question asked Nov 5, 2009 at 17:30 Rakesh JuyalRakesh Juyal 36.8k74 gold badges179 silver badges217 bronze badges 1
  • See this: stackoverflow./questions/5482064/… – Kangkan Commented Mar 31, 2011 at 3:52
Add a ment  | 

3 Answers 3

Reset to default 2

try working from this http://digitalbush./projects/masked-input-plugin

if that does not work, try adapting from this code, changing ti to work for your months:

    function isZipKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && ((charCode < 48 || charCode > 57) && charCode != 45))
        return false;

    return true;
    }

    onkeypress="return isZipKey(this);"

You can set the input to be readonly, and put a div around it that has the onclick set to call the calendar.

That way they can't change the value, but if they click on it they can set a new date.

If you want valid dates, you'll need to validate each keypress. Not a tiger I'd like to tackle personally. If you're not afraid of JavaScript (or JQuery), why not use a calendar GUI like Datepicker

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745408069a4626403.html

相关推荐

  • how can we date mask a text field using javascriptjQuery? - Stack Overflow

    I am having a text field for date. Now i would like to mask this text field so that a user can input on

    5小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信