Regex for AM PM time format for jquery

后端 未结 6 450
耶瑟儿~
耶瑟儿~ 2020-12-09 17:16

I am being frustrated by a regular expression to mask the input field. I want to Limit input to hh:mm AM|PM format and I can\'t get this regex to work.

I use this

6条回答
  •  忘掉有多难
    2020-12-09 18:01

    I have made a jsfiddle example, based on the regular expression of the answer von Yuri: http://jsfiddle.net/Evaqk/

    $('#test1, #test2').blur(function(){
        var validTime = $(this).val().match(/^(0?[1-9]|1[012])(:[0-5]\d) [APap][mM]$/);
        if (!validTime) {
            $(this).val('').focus().css('background', '#fdd');
        } else {
            $(this).css('background', 'transparent');
        }
    });
    

提交回复
热议问题