function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
function fcnMostraFundo() {
fundo.style.display='block';
loading.style.display='block';
return true;
}
function ChecaPIS(pis)
{
var ftap="3298765432";
var total=0;
var i;
var resto=0;
var numPIS=0;
var strResto="";
total=0;
resto=0;
numPIS=0;
strResto="";
numPIS=pis;
if (numPIS=="" || numPIS==null)
{
return false;
}
for(i=0;i<=9;i++)
{
resultado = (numPIS.slice(i,i+1))*(ftap.slice(i,i+1));
total=total+resultado;
}
resto = (total % 11)
if (resto != 0)
{
resto=11-resto;
}
if (resto==10 || resto==11)
{
strResto=resto+"";
resto = strResto.slice(1,2);
}
if (resto!=(numPIS.slice(10,11)))
{
return false;
}
return true;
}
function numbersonly(e, decimal) {
var key;
var keychar;
if (window.event) {
key = window.event.keyCode;
}
else if (e) {
key = e.which;
}
else {
return true;
}
keychar = String.fromCharCode(key);
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) {
return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
return true;
}
else if (decimal && (keychar == ".")) {
return true;
}
else
return false;
}
function IsNumeric(strString , campo)
{
var strValidChars = "0123456789.-,";
var strChar;
var campo = campo;
var blnResult = true;
if (strString.length == 0) return false;
// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}
function NoVirgula(e)
{
var keynum;
var keychar;
var numcheck;
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
keychar = String.fromCharCode(keynum);
if (keynum != 188) return true;
alert('Utilize apenas pontos.');
return false;
}
function fcnNoEnter() {
return !(window.event && window.event.keyCode == 13); }
function fcnMascaraPorcentagem(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;
key = String.fromCharCode(e.keyCode); // Valor para o código da Chave
if (strCheck.indexOf(key) == -1) return false; // Chave inválida
len = objTextBox.value.length;
for(i = 0; i < len; i++)
if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) objTextBox.value = '';
if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += '';
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
objTextBox.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
objTextBox.value += aux2.charAt(i);
objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
}
return false;
}
function fcnMascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789-';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;
key = String.fromCharCode(e.keyCode); // Valor para o código da Chave
if (strCheck.indexOf(key) == -1) return false; // Chave inválida
len = objTextBox.value.length;
for(i = 0; i < len; i++)
if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) objTextBox.value = '';
if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += SeparadorMilesimo;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
objTextBox.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
objTextBox.value += aux2.charAt(i);
objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
}
return false;
}
function disableEnterKey(e)
{
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if(key == 13)
return false;
else
return true;
}
function fcnAjuda(sHelpId) {
fcnNovaTela('ajuda.asp?ac=' + sHelpId, 'no', 'yes', '560', '600')
}
function fcnSubmit(sPagina, sFormulario) {
sFormulario.method='post';
sFormulario.action=sPagina;
sFormulario.submit();
}
function fcnNovaTela(url, bExibeFerramentas, bExibeRolagem, sWidth, sHeight)
{
newwindow=window.open(url, '_blank', 'width=' + sWidth + ',height=' + sHeight + ',left=' + (screen.width - sWidth) / 2 + ',top=' + ((screen.height - sHeight) / 2.0) + ',toolbar=no,location=no,status=no,menubar=' + bExibeFerramentas + ',scrollbars=' + bExibeRolagem + ',resizable=no');
}
function fcnNovaTela2(url, bExibeFerramentas, bExibeRolagem, sWidth, sHeight)
{
newwindow=window.open(url, '_blank', 'width=' + sWidth + ',height=' + sHeight + ',left=' + (screen.width - sWidth) / 2 + ',top=' + ((screen.height - sHeight) / 2.0) + ',toolbar=no,location=no,status=no,menubar=' + bExibeFerramentas + ',scrollbars=' + bExibeRolagem + ',resizable=no');
}
function fcnNovaTelaCheia(url, bExibeFerramentas)
{
newwindow=window.open(url, '_blank', 'width=' + (screen.width - 10) + ',height=' + (screen.height - 57) + ',left=0,top=0,toolbar=no,location=no,status=no,menubar=' + bExibeFerramentas + ',scrollbars=yes,resizable=no,left=0,top=0')
}
function fcnNovaTelaChat(url, bExibeFerramentas, bExibeRolagem, sWidth, sHeight)
{
var telachat=window.open(url, 'telachat', 'width=' + sWidth + ',height=' + sHeight + ',left=' + (screen.width - sWidth) / 2 + ',top=' + ((screen.height - sHeight) / 2.0) + ',toolbar=no,location=no,status=no,menubar=' + bExibeFerramentas + ',scrollbars=' + bExibeRolagem + ',resizable=no')
}
function fcnChecaHora(dt)
{
if (dt.value == '')
return true;
if (dt.value.length != 5)
{
alert('Hora inválida');
dt.select();
return false;
}
var hora = dt.value.substring(0, 2)
var minuto = dt.value.substring(3, 5)
var barra1 = dt.value.substring(2, 3)
if (isNaN(hora))
{
alert('Hora inválida');
dt.select();
return false;
}
if (isNaN(minuto))
{
alert('Hora inválida');
dt.select();
return false;
}
if (barra1 != ':')
{
alert('Hora inválida');
dt.select();
return false;
}
if (hora < 0 || hora > 23)
{
alert('Hora inválida');
dt.select();
return false;
}
if (minuto < 0 || minuto > 59)
{
alert('Hora inválida');
dt.select();
return false;
}
}
function fcnChecaDataRegEx(dateString) {
var regEx = /^\d{4}-\d{2}-\d{2}$/;
if(!dateString.match(regEx)) return false; // Formato inválido
var d = new Date(dateString);
if(!d.getTime() && d.getTime() !== 0) return false; // Data inválida
return d.toISOString().slice(0,10) === dateString;
}
function fcnChecaData(dt)
{
if (dt.value == '')
return true;
if (dt.value.length == 1)
{
dt.value = '';
dt.select();
return true;
}
if ((dt.value.length != 10) || (dt.value.length != 8))
{
if (dt.value.length == 8)
{
var dia_alterando = dt.value.substring(0, 2)
var mes_alterando = dt.value.substring(3, 5)
var ano_alterando = dt.value.substring(6, 10)
if (ano_alterando <= 30)
{
ano_alterando = '20'+ano_alterando
}
else
{
ano_alterando = '19'+ano_alterando
}
dt.value = dia_alterando + '/' + mes_alterando + '/' + ano_alterando;
}
}
else
{
alert('Data inválida');
dt.value = '';
dt.select();
return false;
}
var dia = dt.value.substring(0, 2)
var mes = dt.value.substring(3, 5)
var ano = dt.value.substring(6, 10)
var barra1 = dt.value.substring(2, 3)
var barra2 = dt.value.substring(5, 6)
if (barra1 != '/')
{
alert('Data inválida');
dt.value = '';
dt.select();
return false;
}
if (barra2 != '/')
{
alert('Data inválida');
dt.value = '';
dt.select();
return false;
}
if (dia < 1 || dia > 31)
{
alert('Data inválida');
dt.value = '';
dt.select();
return false;
}
if (mes < 1 || mes > 12)
{
alert('Data inválida');
dt.value = '';
dt.select();
return false;
}
if (ano < 1900 || ano > 2050)
{
alert('Data inválida');
dt.value = '';
dt.select();
return false;
}
}
function fcnChecaIdade(dt)
{
if (dt.value == '')
return true;
if (dt.value.length != 10)
{
alert('Data inválida');
dt.select();
return false;
}
var dia = dt.value.substring(0, 2)
var mes = dt.value.substring(3, 5)
var ano = dt.value.substring(6, 10)
var barra1 = dt.value.substring(2, 3)
var barra2 = dt.value.substring(5, 6)
if (barra1 != '/')
{
alert('Data inválida');
dt.select();
return false;
}
if (barra2 != '/')
{
alert('Data inválida');
dt.select();
return false;
}
if (dia < 1 || dia > 31)
{
alert('Data inválida');
dt.select();
return false;
}
if (mes < 1 || mes > 12)
{
alert('Data inválida');
dt.select();
return false;
}
if (ano < 1900 || ano > 2050)
{
alert('Data inválida');
dt.select();
return false;
}
var data_atual = new Date();
var d = new Date();
var ano_atual = d.getFullYear();
var diferenca = ano_atual - ano;
if (diferenca < 16)
{
var answer = confirm ("Esse funcionário tem somente "+ diferenca +" anos, Confirma essa informação?")
if (answer)
{
}
else
{
dt.select();
document.formulario.txtDataNascimento.value = '';
return false;
}
}
}
function fcnChecaAno(dt)
{
if (dt.value == '')
return true;
if (dt.value.length != 4)
{
alert('Ano inválido');
dt.select();
return false;
}
if (dt.value < 2000 || dt.value > 2050)
{
alert('Ano inválido');
dt.select();
return false;
}
}
function fcnChecaMes(dt)
{
if (dt.value == '')
return true;
if (dt.value < 1 || dt.value > 12)
{
alert('Mês inválido');
dt.select();
return false;
}
}
function fcnMostra(qual)
{
if (qual.style.display=='none') {
qual.style.display='block'
} else {
qual.style.display='none'
}
}
function popUp(URL, w , h)
{
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=175,left = '+winl+',top = '+wint+'');");
}
function finalizar_sessao(sLogin)
{
if (confirm('Tem certeza que deseja finalizar a sessao?'))
window.location=sLogin;
}
function cancelar(sLink)
{
if (confirm('Tem certeza que deseja cancelar?'))
window.location=sLink;
}
function isNUMB(c)
{
if((cx=c.indexOf(","))!=-1)
{
c = c.substring(0,cx)+"."+c.substring(cx+1);
}
if((parseFloat(c) / c != 1))
{
if(parseFloat(c) * c == 0)
{
return(1);
}
else
{
return(0);
}
}
else
{
return(1);
}
}
function LIMP(c)
{
while((cx=c.indexOf("-"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("/"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(","))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("."))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("("))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(")"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(" "))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
return(c);
}
function VerifyCNPJ(CNPJ)
{
CNPJ = LIMP(CNPJ);
if(isNUMB(CNPJ) != 1)
{
return(0);
}
else
{
if(CNPJ == 0)
{
return(0);
}
else
{
g=CNPJ.length-2;
if(RealTestaCNPJ(CNPJ,g) == 1)
{
g=CNPJ.length-1;
if(RealTestaCNPJ(CNPJ,g) == 1)
{
return(1);
}
else
{
return(0);
}
}
else
{
return(0);
}
}
}
}
function RealTestaCNPJ(CNPJ,g)
{
var VerCNPJ=0;
var ind=2;
var tam;
for(f=g;f>0;f--)
{
VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind;
if(ind>8)
{
ind=2;
}
else
{
ind++;
}
}
VerCNPJ%=11;
if(VerCNPJ==0 || VerCNPJ==1)
{
VerCNPJ=0;
}
else
{
VerCNPJ=11-VerCNPJ;
}
if(VerCNPJ!=parseInt(CNPJ.charAt(g)))
{
return(0);
}
else
{
return(1);
}
}
function fcnChecaCnpj(s)
{
if(VerifyCNPJ(s.value) == 1)
{
}
else
{
alert("CNPJ não é válido!");
s.value = '';
s.focus();
return false;
}
return true;
}
function fcnFormataCnpj(Campo, teclapres){
var tecla = teclapres.keyCode;
var vr = new String(Campo.value);
vr = vr.replace(".", "");
vr = vr.replace(".", "");
vr = vr.replace("/", "");
vr = vr.replace("-", "");
tam = vr.length + 1 ;
if (tecla != 9 && tecla != 8){
if (tam > 2 && tam < 6)
Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
if (tam >= 6 && tam < 9)
Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
if (tam >= 9 && tam < 13)
Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
if (tam >= 13 && tam < 15)
Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
}
}
function fcnValidaCpf(sCpf)
{
var iInicia;
iInicia = 0;
sCpf = sCpf.replace("-","");
sCpf = sCpf.replace(".","");
sCpf = sCpf.replace(".","");
sTamanhoCPF = sCpf.length;
if (sTamanhoCPF < 11) iInicia = 1;
if (sCpf == 00000000000) iInicia = 1;
if (sCpf == 11111111111) iInicia = 1;
if (sCpf == 22222222222) iInicia = 1;
if (sCpf == 33333333333) iInicia = 1;
if (sCpf == 44444444444) iInicia = 1;
if (sCpf == 55555555555) iInicia = 1;
if (sCpf == 66666666666) iInicia = 1;
if (sCpf == 77777777777) iInicia = 1;
if (sCpf == 88888888888) iInicia = 1;
if (sCpf == 99999999999) iInicia = 1;
if (sCpf == 10987654321) return true;
if (iInicia == 0)
{
// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = sCpf.substr(9, 2); // Retira os dois últimos dígitos do número informado
// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
DIGITO[I] = sCpf.substr( I, 1);
}
// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
for (I=0; I<=8; I++) {
SOMA = SOMA + DIGITO[I] * POSICAO;
POSICAO = POSICAO - 1;
}
DIGITO[9] = SOMA % 11;
if (DIGITO[9] < 2) {
DIGITO[9] = 0;
}
else{
DIGITO[9] = 11 - DIGITO[9];
}
// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
for (I=0; I<=9; I++) {
SOMA = SOMA + DIGITO[I] * POSICAO;
POSICAO = POSICAO - 1;
}
DIGITO[10] = SOMA % 11;
if (DIGITO[10] < 2) {
DIGITO[10] = 0;
}
else {
DIGITO[10] = 11 - DIGITO[10];
}
// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
if (DV != DV_INFORMADO) {
alert('CPF Inválido')
return false;
}
else {
return true;
}
}
alert('CPF Inválido')
}
function fcnValidaCpfLIberaExp(sCpf)
{
var iInicia;
iInicia = 0;
sCpf = sCpf.replace("-","");
sCpf = sCpf.replace(".","");
sCpf = sCpf.replace(".","");
sTamanhoCPF = sCpf.length;
if (sTamanhoCPF < 11) iInicia = 1;
if (sCpf == 12312312300) return true;
if (sCpf == 00000000000) iInicia = 1;
if (sCpf == 11111111111) iInicia = 1;
if (sCpf == 22222222222) iInicia = 1;
if (sCpf == 33333333333) iInicia = 1;
if (sCpf == 44444444444) iInicia = 1;
if (sCpf == 55555555555) iInicia = 1;
if (sCpf == 66666666666) iInicia = 1;
if (sCpf == 77777777777) iInicia = 1;
if (sCpf == 88888888888) iInicia = 1;
if (sCpf == 99999999999) iInicia = 1;
if (iInicia == 0)
{
// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = sCpf.substr(9, 2); // Retira os dois últimos dígitos do número informado
// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
DIGITO[I] = sCpf.substr( I, 1);
}
// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
for (I=0; I<=8; I++) {
SOMA = SOMA + DIGITO[I] * POSICAO;
POSICAO = POSICAO - 1;
}
DIGITO[9] = SOMA % 11;
if (DIGITO[9] < 2) {
DIGITO[9] = 0;
}
else{
DIGITO[9] = 11 - DIGITO[9];
}
// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
for (I=0; I<=9; I++) {
SOMA = SOMA + DIGITO[I] * POSICAO;
POSICAO = POSICAO - 1;
}
DIGITO[10] = SOMA % 11;
if (DIGITO[10] < 2) {
DIGITO[10] = 0;
}
else {
DIGITO[10] = 11 - DIGITO[10];
}
// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
if (DV != DV_INFORMADO) {
alert('CPF Inválido')
return false;
}
else {
return true;
}
}
alert('CPF Inválido')
}
function fcnMascara(valor, id, mascara, evento)
{
/*
Diego Hellas
diegohellas@gmail.com
Esse script foi desenvolvido com a finalidade de suprir qualquer necessidade
com máscaras em formulários HTML.
Para funcionar corretamente o campo tem que ter obrigatóriamente a propriedade
id no campo input , o script so foi
testado com o evento onkeyup, não sei do comportamento do script com outros eventos
Uma outra caracteristica dele é a verificação do tipo de dado que entra por posição
na máscara comforme a tabelinha a seguir:
***************************
* números * # *
***************************
* qualuqer caratcter * @ *
***************************
*/
/////////////////////////////////////////////////////////////////////////////////
// MODELO //
//onkeyup="mascaraHellas(this.value, this.id, '####.##.##.#######-#/#', event)"//
/////////////////////////////////////////////////////////////////////////////////
if (mascara == '(##)####-####')
{
mascara = '(##)#########';
}
//inicializa a variavel que vai conter o valor final
var valorFinal = "";
//verifica o que foi digitada para que seja verificado se é somente números ou não
var tecla = evento.keyCode;
//manetem o tamanho original do campo sem retirar a máscara
var valorOriginal = valor;
//inicializa um array com todos os caracteres que serão retirado
var arrNaoPermitidos = new Array("-", ".", "/", "\\", "|", "(", ")", ":", " ");
//retira qualquer máscatra que já tenho sido colocada
for(i1=0;i1= valorOriginal.length)
{
//loop em cima do valor do campo sem a máscara
jaTemMascara = false;
for(i=0;i 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + valor.charAt(i);
}
else//se não foi digitado um número é retirado o caracter da string
{
valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
}
}
else if(mascara.charAt(i) == "@")//verifica se o tipo da entrada é qualquer caracter
{
valorFinal = valorFinal + valor.charAt(i);
}
else//se não for quelaquer caracter é algum elemento da máscara
{
//verifica se o próxima depois da máscara é númerica
if(mascara.charAt(i + 1) == "#")
{
//verifica se foi digitado somente números
if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
else//se não foi digitado um número é retirado o caracter da string
{
valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
}
}
else// se não é númerico então pode ser qualuqer caracter
{
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
}
}
else//else da verificação da máscara
{
//verifica se foi digitado somente números
if(mascara.charAt(i + jaTemMascara) == "#")
{
//verifica se foi digitado somente números
if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + valor.charAt(i);
}
else//se não foi digitado um número é retirado o caracter da string
{
valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
}
}
else if(mascara.charAt(i + jaTemMascara) == "@")//verifica se o tipo da entrada é qualquer caracter
{
valorFinal = valorFinal + valor.charAt(i);
}
else
{
//verifica se foi digitado somente números
if(mascara.charAt(i + jaTemMascara +1) == "#")
{
//verifica se foi digitado somente números
if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
else//se não foi digitado um número é retirado o caracter da string
{
valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
}
}
else// se não é númerico então pode ser qualuqer caracter
{
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
}
}//fim da verificação da máscara
}
}
else
{
valorFinal = valorOriginal.substring(0, mascara.length);
}//final da verificação do tamanha máximo da string
}
else
{
//valorFinal = valorOriginal.substring(0, valorOriginal.length -1)
valorFinal = valorOriginal.substring(0, valorOriginal.length);
}//final da verificação do backspace
document.getElementById(id).value = valorFinal;
}
function fcnVoltar()
{
window.history.back();
}
function VerificaEmail (email_campo)
{
var emailStr = email_campo;
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD. 1 means check it, 0 means don't. */
var checkTLD=1;
/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(med|com|br|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
/* The following pattern is used to check if the entered e-mail address
fits the user@domain format. It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/;
/* The following string represents the pattern for matching all special
characters. We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@',;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a
username or domainname. It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";
/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes). E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";
/* The following pattern applies for domains that are IP addresses,
rather than symbolic names. E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/* Finally, let's start trying to figure out if the supplied address is valid. */
/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
alert("O endereco de email parece incorreto. Por favor cheque a localizacao da @ e dos pontos.");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
// Start by checking that only basic ASCII characters are in the strings (0-127).
for (i=0; i127) {
alert("O email contem caracteres invalidos antes da @.");
return false;
}
}
for (i=0; i127) {
alert("O email contem caracteres invalidos depois da @.");
return false;
}
}
// See if "user" is valid
if (user.match(userPat)==null) {
// user is not valid
alert("O email é invalido.");
return false;
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
// this is an IP address
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("O endereço de IP é invalido.");
return false;
}
}
return true;
}
// Domain is symbolic name. Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
//if ((domArr == 'grupofoco,com,br') || (domArr == 'focorh,com,br') || (domArr == 'stantonchaseinternational,com,br') || (domArr == 'yaho,com') || (domArr == 'yaho,com,br') || (domArr == 'globo,com,br') || (domArr == 'zipmail,com') || (domArr == 'hotmail,com,br') || (domArr == 'gmail,com,br')) {
if ((domArr == 'grupofoco,com,br') || (domArr == 'focorh,com,br') || (domArr == 'stantonchaseinternational,com,br') || (domArr == 'yaho,com') || (domArr == 'yaho,com,br') || (domArr == 'globo,com,br') || (domArr == 'zipmail,com') || (domArr == 'gmail,com,br')) {
domArr_disp = domArr;
for (i=0;i, o script so foi
testado com o evento onkeyup, não sei do comportamento do script com outros eventos
Uma outra caracteristica dele é a verificação do tipo de dado que entra por posição
na máscara comforme a tabelinha a seguir:
***************************
* números * # *
***************************
* qualuqer caratcter * @ *
***************************
*/
/////////////////////////////////////////////////////////////////////////////////
// MODELO //
//onkeyup="mascaraHellas(this.value, this.id, '####.##.##.#######-#/#', event)"//
/////////////////////////////////////////////////////////////////////////////////
if (mascara == '(##)####-####')
{
mascara = '(##)#########';
}
//inicializa a variavel que vai conter o valor final
var valorFinal = "";
//verifica o que foi digitada para que seja verificado se é somente números ou não
var tecla = evento.keyCode;
//manetem o tamanho original do campo sem retirar a máscara
var valorOriginal = valor;
//inicializa um array com todos os caracteres que serão retirado
var arrNaoPermitidos = new Array("-", ".", "/", "\\", "|", "(", ")", ":", " ");
//retira qualquer máscatra que já tenho sido colocada
for(i1=0;i1= valorOriginal.length)
{
//loop em cima do valor do campo sem a máscara
jaTemMascara = false;
for(i=0;i 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + valor.charAt(i);
}
else//se não foi digitado um número é retirado o caracter da string
{
valorFinal = valorOriginal.substring(0, valorOriginal.length);
}
}
else if(mascara.charAt(i) == "@")//verifica se o tipo da entrada é qualquer caracter
{
valorFinal = valorFinal + valor.charAt(i);
}
else//se não for quelaquer caracter é algum elemento da máscara
{
//verifica se o próxima depois da máscara é númerica
if(mascara.charAt(i + 1) == "#")
{
//verifica se foi digitado somente números
if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
else//se não foi digitado um número é retirado o caracter da string
{
valorFinal = valorOriginal.substring(0, valorOriginal.length);
}
}
else// se não é númerico então pode ser qualuqer caracter
{
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
}
}
else//else da verificação da máscara
{
//verifica se foi digitado somente números
if(mascara.charAt(i + jaTemMascara) == "#")
{
//verifica se foi digitado somente números
if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + valor.charAt(i);
}
else//se não foi digitado um número é retirado o caracter da string
{
valorFinal = valorOriginal.substring(0, valorOriginal.length);
}
}
else if(mascara.charAt(i + jaTemMascara) == "@")//verifica se o tipo da entrada é qualquer caracter
{
valorFinal = valorFinal + valor.charAt(i);
}
else
{
//verifica se foi digitado somente números
if(mascara.charAt(i + jaTemMascara +1) == "#")
{
//verifica se foi digitado somente números
if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16)
{
//0 = 96 ou 48
//1 = 97 ou 49
//2 = 98 ou 50
//3 = 99 ou 51
//4 = 100 ou 52
//5 = 101 ou 53
//6 = 102 ou 54
//7 = 103 ou 55
//8 = 104 ou 56
//9 = 105 ou 57
//tecla == 9 = tab
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
//else//se não foi digitado um número é retirado o caracter da string
//{
//valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
//}
}
else// se não é númerico então pode ser qualuqer caracter
{
valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
jaTemMascara = jaTemMascara + 1;
}
}
}//fim da verificação da máscara
}
}
else
{
valorFinal = valorOriginal.substring(0, mascara.length);
}//final da verificação do tamanha máximo da string
}
else
{
//valorFinal = valorOriginal.substring(0, valorOriginal.length -1)
valorFinal = valorOriginal.substring(0, valorOriginal.length);
}//final da verificação do backspace
document.getElementById(id).value = valorFinal;
}