JSFiddle - React, Tailwind, and code Playground
by Ashish Kasama
HTML
<input id="firstName" value="Ashish k"></input>
JavaScript
/********************************************************************
* Limit the characters that may be entered in a text field
* Common options: alphanumeric, alphabetic or numeric
* Kevin Sheedy, 2012
* http://github.com/KevinSheedy/jquery.alphanum
*********************************************************************/
(function( $ ){
// API ///////////////////////////////////////////////////////////////////
$.fn.alphanum = function(settings) {
var combinedSettings = getCombinedSettingsAlphaNum(settings);
var $collection = this;
setupEventHandlers($collection, trimAlphaNum, combinedSettings);
return this;
};
$.fn.alpha = function(settings) {
var defaultAlphaSettings = getCombinedSettingsAlphaNum("alpha");
var combinedSettings = getCombinedSettingsAlphaNum(settings, defaultAlphaSettings);
var $collection = this;
setupEventHandlers($collection, trimAlphaNum, combinedSettings);
return this;
};
$.fn.numeric = function(settings) {
var combinedSettings = getCombinedSettingsNum(settings);
var $collection = this;
setupEventHandlers($collection, trimNum, combinedSettings);
$collection.blur(function(){
numericField_Blur(this, settings);
});
return this;
};
// End of API /////////////////////////////////////////////////////////////
// Start Settings ////////////////////////////////////////////////////////
var DEFAULT_SETTINGS_ALPHANUM = {
allow : '', // Allow extra characters
disallow : '', // Disallow extra characters
allowSpace : true, // Allow the space character
allowNumeric : true, // Allow digits 0-9
allowUpper : true, // Allow upper case characters
allowLower : true, // Allow lower case characters
allowCaseless : true, // Allow characters that don't have both upper & lower variants - eg Arabic or Chinese
allowLatin : true, // a-z A-Z
allowOtherCharSets : true, // eg �, �, Arabic, Chinese...