Is there a better way to make sure max length is adhered too? I've noticed that the maxlength and even max value attributes do not work in all browsers for some of the html5 input types:
This is how I would do it to make sure it works, but is there a cleaner alternative?
javascript/jquery:
var checkLength = function(element, maxlength) {
elementValue = $(element).val();
if($(element).val().length > maxlength) {
$(element).val(elementValue.substr(0, maxlength));
};
}
html:
<input name="myNumberField" id="myNumberField" type="tel" onKeyUp="checkLength(this, 5);" />
Any ideas on this one?