$('#total_duration').keyup(function(event) {
this.value = this.value
.replace(/[^\d:]/g, '') // numbers and decimals only
.replace(/(^[\d]{2})[\d]/g, '$1') // not more than 2 digits at the beginning
.replace(/(\::*)\s:/g, '$1') // decimal can't exist more than once
.replace(/(\:[\d]{2})./g, '$1'); // not more than 4 digits after decimal
});
这允许冒号在两位数之后,例如11:12,但我也希望在模式中也使用点(。),例如11.12