From 6416b91ba5087142e7079807157ac65da1729584 Mon Sep 17 00:00:00 2001 From: William Bruno Date: Tue, 8 Dec 2015 13:01:04 -0200 Subject: [PATCH] Include usa phone format --- index.html | 6 +++++- src/jquery.maskx.js | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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 +}());