A jQuery Plugin To Restrict Characters In Text Field - Alphanum

A jQuery Plugin To Restrict Characters In Text Field - Alphanum
File Size: 144 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Alphanum is a small yet useful JQuery plugin that allows you to restrict a text field to only accept specify characters (alphabetic, numeric or alphanumeric characters).

How to use it:

1. Load the latest JQuery javascript library and jQuery Alphanum plugin at the bottom of your web page.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script type="text/javascript" src="jquery.alphanum.js"></script> 

2. Create a text input field on your website.

<input id="demo1">
</input>

3. Initialize the plugin.

<script type="text/javascript">
$('#demo1').alphanum(); // only accepts alphanumeric characters
$('#demo1').alpha(); // only accepts alphabetic characters
$('#demo1').numeric(); // only accepts numeric characters
</script>

4. Available settings for alphahum() method.

// Allow extra characters
allow              : '',    

// Disallow extra characters
disallow           : '',    

// Allow the space character
allowSpace         : true,  

// Allow the newline character \n ascii 10
allowNewline       : true,  

// Allow digits 0-9
allowNumeric       : true,  

// Allow upper case characters
allowUpper         : true,  

// Allow lower case characters
allowLower         : true,  

// Allow characters that don't have both upper & lower variants - eg Arabic or Chinese
allowCaseless      : true,  

// a-z A-Z
allowLatin         : true,  

// eg é, Á, Arabic, Chinese etc
allowOtherCharSets : true,  

// Convert lower case characters to upper case
forceUpper         : false, 

// Convert upper case characters to lower case
forceLower         : false, 

// eg Max Length
maxLength          : NaN    

5. Available settings for numeric() method.

// Allow the + sign
allowPlus           : false, 

// Allow the - sign
allowMinus          : true,  

// Allow the thousands separator, default is the comma eg 12,000
allowThouSep        : true,  

// Allow the decimal separator, default is the fullstop eg 3.141
allowDecSep         : true,  

allowLeadingSpaces  : false,

// The max number of digits
maxDigits           : NaN,  

// The max number of decimal places 
maxDecimalPlaces    : NaN,   

// The max number digits before the decimal point
maxPreDecimalPlaces : NaN,   

// The max numeric value allowed
max                 : NaN,   

// The min numeric value allowed
min                 : NaN    

Change log:

v1.0.26 (2018-04-02)

v1.0.25 (2016-02-19)

  • update

v1.0.19 (2015-12-10)

  • Rebind with new settings

v1.0.16 (2014-01-21)

  • Tidied up the order of the settings after adding forceUpper and forceLower

This awesome jQuery plugin is developed by KevinSheedy. For more Advanced Usages, please check the demo page or visit the official website.