<html>
<body>
<script type="text/javascript">
function check_time()
{
var elem = document.getElementById('timeStr');
var orig_str = elem.value;
//24 hour
var _reg = new RegExp(/^([01][0-9]|2[0-3]):[0-5][0-9]$/);
alert(_reg.test(orig_str));
}
</script>
<input type="text" id="timeStr">
<input type="button" value="test" onclick="check_time()" />
</body>
</html>
You are here: Home > regex > Check Time with a Regular Expression in javascript
Thursday, June 14, 2007
Check Time with a Regular Expression in javascript
copy following code to save a html file, and run it.