Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit fc06ab0

Browse files
committed
Safe check
1 parent 42a160a commit fc06ab0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/jquery.maskx.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,21 @@
4949
classEmpty: 'is-empty'
5050
};
5151
plugin.cc = function (v) {
52+
v = String(v || '');
5253
v = v.replace(/\D/g, "");
5354
v = v.replace(/^(\d{4})(\d)/g, "$1 $2");
5455
v = v.replace(/^(\d{4})\s(\d{4})(\d)/g, "$1 $2 $3");
5556
v = v.replace(/^(\d{4})\s(\d{4})\s(\d{4})(\d)/g, "$1 $2 $3 $4");
5657
return v;
5758
};
5859
plugin.cep = function (v) {
60+
v = String(v || '');
5961
v = v.replace(/\D/g, "");
6062
v = v.replace(/^(\d{5})(\d)/, "$1-$2");
6163
return v;
6264
};
6365
plugin.cnpj = function (v) {
66+
v = String(v || '');
6467
v = v.replace(/\D/g, "");
6568
v = v.replace(/^(\d{2})(\d)/, "$1.$2");
6669
v = v.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3");
@@ -69,51 +72,59 @@
6972
return v;
7073
};
7174
plugin.cpf = function (v) {
75+
v = String(v || '');
7276
v = v.replace(/\D/g, "");
7377
v = v.replace(/(\d{3})(\d)/, "$1.$2");
7478
v = v.replace(/(\d{3})(\d)/, "$1.$2");
7579
v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2");
7680
return v;
7781
};
7882
plugin.dateBR = function (v) {
83+
v = String(v || '');
7984
v = v.replace(/\D/g, "");
8085
v = v.replace(/(\d{2})(\d)/, "$1/$2");
8186
v = v.replace(/(\d{2})(\d)/, "$1/$2");
8287
v = v.replace(/(\d{2})(\d{2})$/, "$1$2");
8388
return v;
8489
};
8590
plugin.hour = function (v) {
91+
v = String(v || '');
8692
v = v.replace(/\D/g, "");
8793
v = v.replace(/(\d{2})(\d)/, "$1h$2");
8894
return v;
8995
};
9096
plugin.money = function (v) {
97+
v = String(v || '');
9198
v = v.replace(/\D/g, "");
9299
v = v.replace(/(\d)(\d{8})$/, "$1.$2");
93100
v = v.replace(/(\d)(\d{5})$/, "$1.$2");
94101
v = v.replace(/(\d)(\d{2})$/, "$1,$2");
95102
return v;
96103
};
97104
plugin.phone = function (v) {
105+
v = String(v || '');
98106
v = v.replace(/\D/g, "");
99107
v = v.replace(/^(\d{2})(\d)/g, "($1) $2");
100108
v = v.replace(/(\d)(\d{4})$/, "$1-$2");
101109
return v;
102110
};
103111
plugin['phone-usa'] = function (v) {
112+
v = String(v || '');
104113
v = v.replace(/\D/g, "");
105114
v = v.replace(/^(\d{3})(\d)/g, "($1) $2");
106115
v = v.replace(/(\d)(\d{4})$/, "$1-$2");
107116
return v;
108117
};
109118
plugin.rg = function (v) {
119+
v = String(v || '');
110120
v = v.replace(/\D/g, "");
111121
v = v.replace(/(\d)(\d{7})$/, "$1.$2");
112122
v = v.replace(/(\d)(\d{4})$/, "$1.$2");
113123
v = v.replace(/(\d)(\d)$/, "$1-$2");
114124
return v;
115125
};
116126
plugin.time = function (v) {
127+
v = String(v || '');
117128
v = v.replace(/\D/g, "");
118129
v = v.replace(/(\d{1})(\d{2})(\d{2})/, "$1:$2.$3");
119130
return v;

0 commit comments

Comments
 (0)