Skip to content

Commit

Permalink
Include usa phone format
Browse files Browse the repository at this point in the history
  • Loading branch information
William Bruno committed Dec 8, 2015
1 parent aa76512 commit 6416b91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@


jQuery('input[name="telefone"]').maskx({maskx: 'phone'});
jQuery('input[name="telefone-usa"]').maskx({maskx: 'phone-usa'});

jQuery('input[name="peso"]').maskx({maskx: 'weight'});
});
Expand Down Expand Up @@ -92,9 +93,12 @@ <h1>Plugin jQuery.maskx com REGEX</h1>
<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>
</html>
8 changes: 7 additions & 1 deletion src/jquery.maskx.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
v = v.replace(/(\d)(\d{4})$/, "$1-$2");
return v;
};
plugin['phone-usa'] = function (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 = v.replace(/\D/g, "");
v = v.replace(/(\d)(\d{7})$/, "$1.$2");
Expand All @@ -110,4 +116,4 @@
v = v.replace(/(\d{1})(\d{2})(\d{2})/, "$1:$2.$3");
return v;
};
}());
}());

0 comments on commit 6416b91

Please sign in to comment.