Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from kharlamov/an-clean-and-copypaste

alphanumeric enhancements and cleanup.
  • Loading branch information...
commit e2ae1779f7a3de6687f47fd3779de9edd1966611 2 parents e7b11c1 + 730100c
John Antoni Griffiths authored
Showing with 61 additions and 71 deletions.
  1. +60 −70 jquery.alphanumeric.js
  2. +1 −1  jquery.alphanumeric.pack.js
View
130 jquery.alphanumeric.js
@@ -1,82 +1,72 @@
-(function($){
+(function ($) {
+ $.fn.alphanumeric = function (p) {
+ var input = $(this),
+ az = "abcdefghijklmnopqrstuvwxyz",
+ options = $.extend({
+ ichars: '!@#$%^&*()+=[]\\\';,/{}|":<>?~`.- _',
+ nchars: '',
+ allow: ''
+ }, p),
+ s = options.allow.split(''),
+ i = 0,
+ ch,
+ regex;
- $.fn.alphanumeric = function(p) {
+ for (i; i < s.length; i++) {
+ if (options.ichars.indexOf(s[i]) != -1) {
+ s[i] = '\\' + s[i];
+ }
+ }
- p = $.extend({
- ichars: "!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- ",
- nchars: "",
- allow: ""
- }, p);
+ if (options.nocaps) {
+ options.nchars += az.toUpperCase();
+ }
+ if (options.allcaps) {
+ options.nchars += az;
+ }
- return this.each
- (
- function()
- {
+ options.allow = s.join('|');
- if (p.nocaps) p.nchars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- if (p.allcaps) p.nchars += "abcdefghijklmnopqrstuvwxyz";
-
- s = p.allow.split('');
- for ( i=0;i<s.length;i++) if (p.ichars.indexOf(s[i]) != -1) s[i] = "\\" + s[i];
- p.allow = s.join('|');
-
- var reg = new RegExp(p.allow,'gi');
- var ch = p.ichars + p.nchars;
- ch = ch.replace(reg,'');
+ regex = new RegExp(options.allow, 'gi');
+ ch = (options.ichars + options.nchars).replace(regex, '');
- $(this).keypress
- (
- function (e)
- {
-
- if (!e.charCode) k = String.fromCharCode(e.which);
- else k = String.fromCharCode(e.charCode);
-
- if (ch.indexOf(k) != -1) e.preventDefault();
- if (e.ctrlKey&&k=='v') e.preventDefault();
-
- }
-
- );
-
- $(this).bind('contextmenu',function () {return false});
-
- }
- );
+ input.keypress(function (e) {
+ var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
- };
+ if (ch.indexOf(key) != -1 && !e.ctrlKey) {
+ e.preventDefault();
+ }
+ });
- $.fn.numeric = function(p) {
-
- var az = "abcdefghijklmnopqrstuvwxyz";
- az += az.toUpperCase();
+ input.blur(function () {
+ var value = input.val(),
+ j = 0;
- p = $.extend({
- nchars: az
- }, p);
-
- return this.each (function()
- {
- $(this).alphanumeric(p);
- }
- );
-
- };
-
- $.fn.alpha = function(p) {
+ for (j; j < value.length; j++) {
+ if (ch.indexOf(value[j]) != -1) {
+ input.val('');
+ return false;
+ }
+ }
+ return false;
+ });
- var nm = "1234567890";
+ return input;
+ };
- p = $.extend({
- nchars: nm
- }, p);
+ $.fn.numeric = function (p) {
+ var az = 'abcdefghijklmnopqrstuvwxyz',
+ aZ = az.toUpperCase();
- return this.each (function()
- {
- $(this).alphanumeric(p);
- }
- );
-
- };
+ return this.each(function () {
+ $(this).alphanumeric($.extend({ nchars: az + aZ }, p));
+ });
+ };
-})(jQuery);
+ $.fn.alpha = function (p) {
+ var nm = '1234567890';
+ return this.each(function () {
+ $(this).alphanumeric($.extend({ nchars: nm }, p));
+ });
+ };
+})(jQuery);
View
2  jquery.alphanumeric.pack.js
@@ -1 +1 @@
-eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(2($){$.c.f=2(p){p=$.d({g:"!@#$%^&*()+=[]\\\\\\\';,/{}|\\":<>?~`.- ",4:"",9:""},p);7 3.b(2(){5(p.G)p.4+="Q";5(p.w)p.4+="n";s=p.9.z(\'\');x(i=0;i<s.y;i++)5(p.g.h(s[i])!=-1)s[i]="\\\\"+s[i];p.9=s.O(\'|\');6 l=N M(p.9,\'E\');6 a=p.g+p.4;a=a.H(l,\'\');$(3).J(2(e){5(!e.r)k=o.q(e.K);L k=o.q(e.r);5(a.h(k)!=-1)e.j();5(e.u&&k==\'v\')e.j()});$(3).B(\'D\',2(){7 F})})};$.c.I=2(p){6 8="n";8+=8.P();p=$.d({4:8},p);7 3.b(2(){$(3).f(p)})};$.c.t=2(p){6 m="A";p=$.d({4:m},p);7 3.b(2(){$(3).f(p)})}})(C);',53,53,'||function|this|nchars|if|var|return|az|allow|ch|each|fn|extend||alphanumeric|ichars|indexOf||preventDefault||reg|nm|abcdefghijklmnopqrstuvwxyz|String||fromCharCode|charCode||alpha|ctrlKey||allcaps|for|length|split|1234567890|bind|jQuery|contextmenu|gi|false|nocaps|replace|numeric|keypress|which|else|RegExp|new|join|toUpperCase|ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('|'),0,{}));
+eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(3($){$.h.k=3(p){6 b=$(8),l="n",2=$.m({f:\'!@#$%^&*()+=[]\\\\\\\';,/{}|":<>?~`.- O\',4:\'\',c:\'\'},p),s=2.c.N(\'\'),i=0,9,d;t(i;i<s.w;i++){5(2.f.g(s[i])!=-1){s[i]=\'\\\\\'+s[i]}}5(2.L){2.4+=l.q()}5(2.K){2.4+=l}2.c=s.J(\'|\');d=y D(2.c,\'A\');9=(2.f+2.4).I(d,\'\');b.z(3(e){6 a=B.C(!e.v?e.E:e.v);5(9.g(a)!=-1&&!e.F){e.G()}});b.H(3(){6 a=b.u(),j=0;t(j;j<a.w;j++){5(9.g(a[j])!=-1){b.u(\'\');7 o}}7 o});7 b};$.h.M=3(p){6 a=\'n\',x=a.q();7 8.r(3(){$(8).k($.m({4:a+x},p))})};$.h.P=3(p){6 a=\'Q\';7 8.r(3(){$(8).k($.m({4:a},p))})}})(R);',54,54,'||options|function|nchars|if|var|return|this|ch|||allow|regex||ichars|indexOf|fn|||alphanumeric|az|extend|abcdefghijklmnopqrstuvwxyz|false||toUpperCase|each||for|val|charCode|length|aZ|new|keypress|gi|String|fromCharCode|RegExp|which|ctrlKey|preventDefault|blur|replace|join|allcaps|nocaps|numeric|split|_|alpha|1234567890|jQuery'.split('|'),0,{}))
Please sign in to comment.
Something went wrong with that request. Please try again.