-
Notifications
You must be signed in to change notification settings - Fork 2
/
maoli.min.js
4 lines (4 loc) · 1.75 KB
/
maoli.min.js
1
2
3
4
(function(n){var k=n.Maoli||{},m=function(g){var h=g;return h="function"!==typeof String.prototype.trim?g.replace(/^\s\s*/,"").replace(/\s\s*$/,""):g.trim()};n.Maoli=k;k.version="0.2.5";k.Cep=function(){var g={loose:"^(\\d{5}-\\d{3}|\\d{8})$",strict:"^(\\d{5}-\\d{3})$"};return{validate:function(h,a){var d=null;a=a||"loose";h=m(h||"");if(!g[a])return!1;d=new RegExp(g[a],"gi");return d.test(h)?!0:!1}}}();k.Cpf=function(){var g={loose:"^(\\d{3}\\.\\d{3}\\.\\d{3}-\\d{2})|(\\d{11})$",strict:"^\\d{3}\\.\\d{3}\\.\\d{3}-\\d{2}$"},
h=function(a){for(var d=a.length-1,f=0,b=0;-1<d;)f+=parseInt(a.substring(d,d+1),10)*(a.length+1-d),d-=1;b=11-f%11;if(10===b||11===b)b=0;return b};return{validate:function(a,d){var f=0,b=0,c=0,e=0,f=!1;c=null;b=a||"";c=d||"loose";b=m(b);""!==b&&g[c]?(c=new RegExp(g[c],"gi"),b=c.test(b)?!0:!1):b=!1;if(!b)return f;a=m(a).toLowerCase().replace(/\./g,"").replace(/-/g,"");f=parseInt(a.substring(9,10),10);b=parseInt(a.substring(10,11),10);c=h(a.substring(0,9));e=h(a.substring(0,10));return f===c&&b===e}}}();
k.Cnpj=function(){var g=[5,4,3,2,9,8,7,6,5,4,3,2],h=[6,5,4,3,2,9,8,7,6,5,4,3,2],a={loose:"^(\\d{2}\\.\\d{3}\\.\\d{3}\\/\\d{4}-\\d{2})|(\\d{14})$",strict:"^\\d{2}\\.\\d{3}\\.\\d{3}\\/\\d{4}-\\d{2}$"},d=function(a,b){for(var c=a.length-1,e=0,d=0;-1<c;)e+=parseInt(a.substring(c,c+1),10)*b[c],c-=1;d=e%11;return 2>d?0:11-d};return{validate:function(f,b){var c=0,e=0,l=0,k=0,c=!1;l=null;e=f||"";l=b||"loose";e=m(e);""!==e&&a[l]?(l=new RegExp(a[l],"gi"),e=l.test(e)?!0:!1):e=!1;if(!e)return c;f=m(f).toLowerCase().replace(/\./g,
"").replace(/-/g,"").replace(/\//g,"");c=parseInt(f.substring(12,13),10);e=parseInt(f.substring(13,14),10);l=d(f.substring(0,12),g);k=d(f.substring(0,13),h);return c===l&&e===k}}}();void 0!==module&&(module.exports=k)})(this);