jquery.allowed-chars
Version:
jQuery plugin to restrict users for typing only allowed chars for specified element
3 lines • 1.24 kB
JavaScript
/*! jquery.allowed-chars 03-06-2014 jQuery Allowed Chars - simple plugin v1.0.4 Copyright (c) 2014 Pavlo Voznenko and other contributors. Distributed under the MIT license. https://github.com/fosco-maestro/jquery-allowed-chars-simple-plugin */
!function(a,b){"use strict";a.fn.allowedChars=function(c){var d={allowed:"0123456789",caseSensitive:!0},e=a(this),f={init:function(c){if(b!==c){var e=Object.prototype.toString.call(c);switch(e){case"[object RegExp]":case"[object String]":d.allowed=c;break;case"[object Object]":a.extend(d,c);break;default:return f.errorHandler("Unexpected 'options' type: "+e+"; Supported types: RegExp, String, Object"),!1}}return!0},errorHandler:function(a){b!==console&&b!==console.log&&console.log("jquery.allowedChars error: "+a)}};f.init(c)&&e.keypress(function(a){var c,e=window.event?window.event.keyCode:a.keyCode||a.charCode||b,f=d.allowed,g="[object RegExp]"===Object.prototype.toString.call(f);if(e===b)return!0;if(c=String.fromCharCode(e),g)f.test(c)||a.preventDefault();else{if(d.caseSensitive||(f=f.toLowerCase(),c=c.toLowerCase()),-1!==f.indexOf(c))return!0;var h=-1===[null,0,8,9,13,27].indexOf(e);h&&a.preventDefault()}return!0})}}(jQuery);
//# sourceMappingURL=jquery.allowed-chars.min.map