I have to build an HTML Form with an Input text field for Hours and Minutes.
Something like:
Name : [Foo]
Surname
Either with the following regular expression :
^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$
Or by hand, but I strongly suggest the RegExp :) A simple example :
function validateHhMm(inputField) {
var isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(inputField.value);
if (isValid) {
inputField.style.backgroundColor = '#bfa';
} else {
inputField.style.backgroundColor = '#fba';
}
return isValid;
}