Created
May 29, 2014 22:38
-
-
Save edtoken/b09ead4a5a6e5b7bc8b9 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
$(document).on('keyup', '.numeric', function(e){ | |
var val = false; | |
var sKeys = [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 144]; | |
var re = /^[0-9]*$/; | |
var text = String.fromCharCode(e.keyCode); | |
if(this.value){ | |
val = this.value; | |
}else if(this.innerHTML){ | |
val = this.innerHTML; | |
} | |
if(!re.test(text) && val !== '' && sKeys.indexOf(e.keyCode) < 0 || (val !== false && !re.test(val))){ | |
$(this).addClass('input-error'); | |
return false; | |
} | |
$(this).removeClass('input-error'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment