jQuery Allowed Chars simple plugin
jQuery plugin to restrict users for typing only allowed chars for specified element
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.allowed-chars/1.0.2/jquery.allowed-chars.min.js"></script>
Only integer chars [0123456789]:
<br/>
<input type='text' id="int" />
<br/>
<br/>Custom chars [a, B, 1, {space}, _]:
<br/>
<input type='text' id="custom" />
<br/>
<br/>RegExp [/\d/] -- only integers:
<br/>
<input type='text' id="regexp" />
<br/>
<br/>Custom chars [A, b, s, D] not case sensitive, full options:
<br/>
<input type='text' id="full" />
JavaScript
$(function () {
// by default only integers are allowed
$('#int').allowedChars();
// you can specified another list of chars that allowed,
// list is case sensitive
// you can use regular expression
$('#regexp').allowedChars(/\d/);
// you can send object with options.
// For example list of allowed chars and make check not case sensitive
$('#full').allowedChars({
allowed:'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890 ',
caseSensitive: false, notallowed:'{space}',
});
});