Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

Commit

Permalink
Add maxlength check (ie9 and below)
Browse files Browse the repository at this point in the history
- throws an error when value.length > maxlength but does not prevent you from typing > maxlength
- tested in ie7 & ie9
  • Loading branch information
uglymunky committed Sep 18, 2012
1 parent fa67d3f commit 0ff1f50
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions jquery.h5validate.js
Expand Up @@ -218,7 +218,8 @@
errorID,
required,
validity,
$checkRequired;
$checkRequired,
maxlength;

pattern = $this.filter('[pattern]')[0] ? $this.attr('pattern') : false,

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
});
Expand Down

0 comments on commit 0ff1f50

Please sign in to comment.