Skip to content

Commit

Permalink
Safe check
Browse files Browse the repository at this point in the history
  • Loading branch information
wbruno committed Mar 17, 2016
1 parent 42a160a commit fc06ab0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/jquery.maskx.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@
classEmpty: 'is-empty'
};
plugin.cc = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/^(\d{4})(\d)/g, "$1 $2");
v = v.replace(/^(\d{4})\s(\d{4})(\d)/g, "$1 $2 $3");
v = v.replace(/^(\d{4})\s(\d{4})\s(\d{4})(\d)/g, "$1 $2 $3 $4");
return v;
};
plugin.cep = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/^(\d{5})(\d)/, "$1-$2");
return v;
};
plugin.cnpj = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/^(\d{2})(\d)/, "$1.$2");
v = v.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3");
Expand All @@ -69,51 +72,59 @@
return v;
};
plugin.cpf = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/(\d{3})(\d)/, "$1.$2");
v = v.replace(/(\d{3})(\d)/, "$1.$2");
v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2");
return v;
};
plugin.dateBR = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/(\d{2})(\d)/, "$1/$2");
v = v.replace(/(\d{2})(\d)/, "$1/$2");
v = v.replace(/(\d{2})(\d{2})$/, "$1$2");
return v;
};
plugin.hour = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/(\d{2})(\d)/, "$1h$2");
return v;
};
plugin.money = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/(\d)(\d{8})$/, "$1.$2");
v = v.replace(/(\d)(\d{5})$/, "$1.$2");
v = v.replace(/(\d)(\d{2})$/, "$1,$2");
return v;
};
plugin.phone = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/^(\d{2})(\d)/g, "($1) $2");
v = v.replace(/(\d)(\d{4})$/, "$1-$2");
return v;
};
plugin['phone-usa'] = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/^(\d{3})(\d)/g, "($1) $2");
v = v.replace(/(\d)(\d{4})$/, "$1-$2");
return v;
};
plugin.rg = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/(\d)(\d{7})$/, "$1.$2");
v = v.replace(/(\d)(\d{4})$/, "$1.$2");
v = v.replace(/(\d)(\d)$/, "$1-$2");
return v;
};
plugin.time = function (v) {
v = String(v || '');
v = v.replace(/\D/g, "");
v = v.replace(/(\d{1})(\d{2})(\d{2})/, "$1:$2.$3");
return v;
Expand Down

0 comments on commit fc06ab0

Please sign in to comment.