Created
October 22, 2010 14:35
-
-
Save arnekolja/640640 to your computer and use it in GitHub Desktop.
Simplest way to allowing only given regular expressions in an input field. Uses jQuery for selecting the element though, you might want to change this.
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
$(document).ready( function() { | |
$("input.alphanumeric").keypress(function (e) { | |
if (String.fromCharCode(e.keyCode).search(/[0-9A-Za-z]/) == -1) return false; | |
}); | |
$("input.numeric").keypress(function (e) { | |
if (String.fromCharCode(e.keyCode).search(/[0-9]/) == -1) return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment