From 0ff1f5059d5ea5589597fe2331c093d1ef3ba9b1 Mon Sep 17 00:00:00 2001 From: uglymunky Date: Tue, 18 Sep 2012 02:22:40 -0700 Subject: [PATCH] Add maxlength check (ie9 and below) - throws an error when value.length > maxlength but does not prevent you from typing > maxlength - tested in ie7 & ie9 --- jquery.h5validate.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jquery.h5validate.js b/jquery.h5validate.js index aaa45c7..9d65d41 100755 --- a/jquery.h5validate.js +++ b/jquery.h5validate.js @@ -218,7 +218,8 @@ errorID, required, validity, - $checkRequired; + $checkRequired, + maxlength; pattern = $this.filter('[pattern]')[0] ? $this.attr('pattern') : false, @@ -256,6 +257,12 @@ console.log('Regex test: ' + re.test(value) + ', Pattern: ' + pattern); // **DEBUG } + maxlength = $this.attr('maxlength'); + if (maxlength !== undefined && value.length > maxlength) { + validity.valid = false; + validity.tooLong = true; + } + if (required && !value) { validity.valid = false; validity.valueMissing = true; @@ -369,11 +376,14 @@ buildSettings = function buildSettings(options) { // Combine defaults and options to get current settings. var settings = $.extend({}, defaults, options, methods), - activeClass = settings.classPrefix + settings.activeClass; + activeClass = settings.classPrefix + settings.activeClass, + activeValidationElements = !('maxLength' in document.createElement('textarea')) + ? ', [maxlength]' + : ''; return $.extend(settings, { activeClass: activeClass, - activeClassSelector: '.' + activeClass, + activeClassSelector: '.' + activeClass + activeValidationElements, requiredClass: settings.classPrefix + settings.requiredClass, el: this });