-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
107 lines (77 loc) · 2.64 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<html>
<head>
<meta charset="utf-8" />
<title>Plugin jQuery.maskx - REGEX</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="src/jquery.maskx.js"></script>
<script type="text/javascript">
jQuery.fn.maskx.user_defined = function(v){
v = v.replace(/\D/g, "");
v = v.replace(/(\d{3})(\d)/, "$1/$2");
v = v.replace(/(\d+)(\d{2})$/, "$1-$2");
return v;
};
function zeroFill(amount) {
var fill = '';
while(amount--) {
fill += '0';
}
return fill;
}
jQuery.fn.maskx.weight = function(v){
var integer = 0,
c = '';
v = v + '';
integer = v.split(',')[0];
v = v.replace(/\D/g, "");
v = v.replace(/^[0]+/, "");
if(v.length <= 4 || !integer)
{
c = zeroFill(4 - v.length);
v = '0,' + c + v;
} else {
v = v.replace(/^(\d{1,})(\d{4})$/, "$1,$2");
}
return v;
};
jQuery(document).ready(function(){
console.log(jQuery.maskx.user_defined('05570060'));
jQuery('.cartoes').maskx({maskx: 'cc'});//pela class
jQuery('#input_dinheiro').maskx({maskx: 'money'});//pelo id
jQuery('input[name="dinheiro"]').maskx({maskx: 'money'});//pelo name
jQuery('input[name="cep"]').maskx({maskx: 'cep'});
jQuery('input[name="other"]').maskx({maskx: 'user_defined'});
jQuery('input[name="telefone"]').maskx({maskx: 'phone'});
jQuery('input[name="telefone-usa"]').maskx({maskx: 'phone-usa'});
jQuery('input[name="peso"]').maskx({maskx: 'weight'});
});
</script>
<style type="text/css">
label span,
label { display: block; }
label { margin-bottom: 10px; }
</style>
</head>
<body>
<h1>Plugin jQuery.maskx com REGEX</h1>
<label><span>Cartão de Crédito Visa</span>
<input type="number" name="NumeroCC" class="cartoes" maxlength="19" pattern="[0-9]{4}\s[0-9]{4}\s[0-9]{4}\s[0-9]{4}" /></label>
<label><span>Cartão de Crédito MasterCard</span>
<input type="number" name="NumeroCC" class="cartoes" maxlength="19" /></label>
<label><span>Dinheiro 2</span>
<input type="text" name="dinheiro2" id="input_dinheiro" maxlength="14" /></label>
<label><span>Dinheiro</span>
<input type="text" name="dinheiro" maxlength="14" /></label>
<label><span>CEP</span>
<input type="text" name="cep" maxlength="9" /></label>
<label><span>Other</span>
<input type="text" name="other" maxlength="9" /></label>
<label><span>Telefone</span>
<input type="text" name="telefone" maxlength="15" /></label>
<label><span>Telefone (USA)</span>
<input type="text" name="telefone-usa" maxlength="14" /></label>
<label><span>Peso</span>
<input type="text" name="peso" maxlength="8" /></label>
</body>
</html>