Looking at your answer I think you should use instead
/^[0-5]?\d:[0-5]\d/
Here's an interactive example :
<!DOCTYPE html>
<html>
<head>
<title>Form validation</title>
</head>
<body>
<h1>Form validation question</h1>
<p>This is an example that shows test answers for the question</p>
<form name="example">
<input onchange="updateResult(this.value)" /><br />
<p id="result"></p>
</form>
<script>
function updateResult(text_entered){
var output_text_element = document.getElementById("result");
var pattern = /^[0-5]?\d:[0-5]\d/;
if (pattern.test(text_entered)) {
output_text_element.innerHTML = "Valid time";
} else {
output_text_element.innerHTML = "Invalid time";
}
};
</script>
</body>
</html>
This code says:
- Valid time for 2:34
- Valid time for 32:34
- Invalid time for 32:64
- Invalid time for 82:64
- Invalid time for 82:14