Created
August 31, 2011 13:05
-
-
Save cristobal/1183493 to your computer and use it in GitHub Desktop.
jQuery Numeric - Number validator
This file contains 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.js | |
* | |
* @author Cristobal Dabed | |
* @version 0.1 | |
*/ | |
(function ($) { | |
var re = new RegExp('[A-Za-z\\]\\[!\\"#$%&\'()*+,.\\/:;<=>?@\\^_`{|}~-]'); | |
var re_s = new RegExp("\\D"); | |
$.fn.numeric = function(strict) { | |
return $(this).bind("keydown keypress keyup", function(event) { | |
$(this).val( | |
$(this).val().replace((strict ? re_s : re), "") | |
); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment