Created
February 25, 2019 10:02
-
-
Save deckameron/786100e3bd43394d24b64a86451b0d57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.MaskInteger = function(v){ | |
return v.replace(/\D/g,""); | |
}; | |
/*Função que padroniza telefone (11) 94184-1241*/ | |
exports.MaskTelephone = function(v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/^(\d{2})(\d)/g,"($1) $2"); | |
v=v.replace(/(\d)(\d{4})$/,"$1-$2"); | |
return v; | |
}; | |
/*Função que padroniza telefone (11) 41841241*/ | |
exports.MaskTelephoneCall = function (v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/^(\d\d)(\d)/g,"($1) $2"); | |
return v; | |
}; | |
/*Função que padroniza CPF*/ | |
exports.MaskCpf = function(v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/(\d{3})(\d)/,"$1.$2"); | |
v=v.replace(/(\d{3})(\d)/,"$1.$2"); | |
v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2"); | |
return v; | |
}; | |
/*Função que padroniza CEP*/ | |
exports.MaskCep = function(v){ | |
v=v.replace(/D/g,""); | |
v=v.replace(/^(\d{5})(\d)/,"$1-$2"); | |
return v; | |
}; | |
/*Função que padroniza CNPJ*/ | |
exports.MaskCnpj = function (v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/^(\d{2})(\d)/,"$1.$2"); | |
v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3"); | |
v=v.replace(/\.(\d{3})(\d)/,".$1/$2"); | |
v=v.replace(/(\d{4})(\d)/,"$1-$2"); | |
return v; | |
}; | |
/*Função que permite apenas numeros Romanos*/ | |
exports.MaskRomanNumbers = function(v){ | |
v=v.toUpperCase(); | |
v=v.replace(/[^IVXLCDM]/g,""); | |
while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="") | |
v=v.replace(/.$/,""); | |
return v; | |
}; | |
/*Função que padroniza o Site*/ | |
exports.MaskWebsiteUrl = function(v){ | |
v=v.replace(/^http:\/\/?/,""); | |
dominio=v; | |
caminho=""; | |
if(v.indexOf("/") > -1) { | |
dominio = v.split("/")[0]; | |
} | |
caminho=v.replace(/[^\/]*/,""); | |
dominio=dominio.replace(/[^\w\.\+-:@]/g,""); | |
caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,""); | |
caminho=caminho.replace(/([\?&])=/,"$1"); | |
if(caminho!="")dominio=dominio.replace(/\.+$/,"") | |
v="http://"+dominio+caminho | |
return v; | |
}; | |
/*Função que padroniza DATA*/ | |
exports.MaskDate = function(v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/(\d{2})(\d)/,"$1/$2"); | |
v=v.replace(/(\d{2})(\d)/,"$1/$2"); | |
return v; | |
}; | |
/*Função que padroniza HORA*/ | |
exports.MaskHour = function(v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/(\d{2})(\d)/,"$1:$2"); | |
return v; | |
}; | |
/*Função que padroniza valor monétario*/ | |
exports.MaskMoney = function(v){ | |
v=v.replace(/\D/g,""); //Remove tudo o que não é dígito | |
v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2"); | |
//v=v.replace(/(\d{3})(\d)/g,"$1,$2") | |
v=v.replace(/(\d)(\d{2})$/,"$1.$2"); //Coloca ponto antes dos 2 últimos digitos | |
return v; | |
}; | |
/*Função que padroniza Area*/ | |
exports.MaskArea = function(v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/(\d)(\d{2})$/,"$1.$2"); | |
return v; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment