diff --git a/index.html b/index.html index 364551e..3e8c3f7 100644 --- a/index.html +++ b/index.html @@ -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'}); }); @@ -92,9 +93,12 @@

Plugin jQuery.maskx com REGEX

+ + - \ No newline at end of file + diff --git a/src/jquery.maskx.js b/src/jquery.maskx.js index 9e3d320..daf5a05 100644 --- a/src/jquery.maskx.js +++ b/src/jquery.maskx.js @@ -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"); @@ -110,4 +116,4 @@ v = v.replace(/(\d{1})(\d{2})(\d{2})/, "$1:$2.$3"); return v; }; -}()); \ No newline at end of file +}());