Created
March 11, 2010 14:32
-
-
Save lucasmazza/329162 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Minimal MaxLength validation on jQuery | |
| // Expected markup : <textarea class="maxlen 250"></textarea> | |
| jQuery("textarea.maxlen").live("keyup", function(event) { | |
| var max = parseInt(this.className.match(/\d+/)); | |
| var key = event.which; | |
| if (max && (key >= 33 || key == 13)) { | |
| if (this.value.length >= max) { | |
| this.value = this.value.substr(0, max); | |
| event.preventDefault(); | |
| } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Numeric only input | |
| jQuery("input.numerical").live("keyup", function(event) { | |
| var key = event.which; | |
| jQuery(this).val(this.value.replace(/\D/ig, "")); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment