Skip to content

Instantly share code, notes, and snippets.

@devluis
Created December 14, 2013 04:34
Show Gist options
  • Save devluis/7955716 to your computer and use it in GitHub Desktop.
Save devluis/7955716 to your computer and use it in GitHub Desktop.
Add separator in string time with jquery
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add separator in time with Jquery</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#currentTime").keyup(function(){
if ($(this).val().length == 2){
$(this).val($(this).val() + ":");
}else if ($(this).val().length == 5){
$(this).val($(this).val() + ":");
}
});
});
</script>
</head>
<body>
<form id="myForm">
<input type="text" name="currentTime" id="currentTime" maxlength="8">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment