Skip to content

Instantly share code, notes, and snippets.

@glebtv
Created November 23, 2013 05:48
Show Gist options
  • Save glebtv/7611291 to your computer and use it in GitHub Desktop.
Save glebtv/7611291 to your computer and use it in GitHub Desktop.
$('.timep input').off('blur').blur(function() {
var $t = $(this), v = $t.val();
v = v.replace(':', '');
v = v.replace('-', '');
if (v > 2400) {
v = '0000';
}
if (v.match(/\d{4}/)) {
$t.val(v.substr(0, 2) + ':' + v.substr(2, 2));
} else if (v.match(/\d{2}/)) {
$t.val(v.substr(0, 2) + ':00');
} else if (v.match(/\d{2}:\d{2}/)) {
} else {
$t.val('00:00');
}
var i = $t.val().substr(0, 2) + $t.val().substr(3, 2);
i = i * 1;
if (i < 0 || i > 2400) {
$t.val('00:00');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment