简体   繁体   中英

How to prevent input values of hour and minute in specific format (hh:mm)

I have one input field for time entry and it needs to enter hour and minute in hh:mm format. Only numbers can be allowed and additional unnecessary data are restricted. So could you have some solution for this issue using or or something that will be OK. Thank you.

 <form>
      <input pattern="\d{1,2}:\d{1,2}" id="Date" required="required" maxlength="5">
      <input type="submit">
 </form> 

Scrpit

$(document).ready(function(){
    $('#Date').keypress(validateNumber);
});

function validateNumber(event) {
    var key = window.event ? event.keyCode : event.which;
    if (key < 48 || key > 58) {
        return false;
    } else {
        return true;
    }
};

See

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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