//====================================== //Nome: GenJsValidateTelefone //Linguagem: JScript //Descrição: Essa função recebe um telefone e valida sua máscara // //Autor: Equipe Biblioteca Marlin // //Data: 12/06/2002 // //Parâmetros de entrada: // - pStrFormattedR => Telefone de retorno formatado // - pStrToValidate => Telefone a ser validado // - pIntType => O tipo do telefone // 1 - todos // 2 - fixo // 3 - celular // - pIntOptional => Se o Telefone é opcional ou obrigatório // 0 - obrigatório // 1 - opcional // - //Retorno: Código de erro // //Informações adicionais: // + Funções: // - FncJsVerifyIntParameter(pIntParameter, pIntDefValue) // - // + Includes: // - // + Objetos: // - // + Stored Procedures: // - //Historico Alteracao: // - 04/07/2002 Thyago Consort // - //====================================== function GenJsValidateTelefone(pStrFormattedR, pStrToValidate, pIntType, pIntOptional){ var lObjRegExp; var lStrRegExp; var lStrFormatted; var p = new Array; lStrFormatted = pStrToValidate; lStrFormatted = lStrFormatted.replace(/^\s*/, ''); lStrFormatted = lStrFormatted.replace(/\s*$/, ''); pStrFormattedR[0] = pStrToValidate; //Verificando parâmetros de entrada e valores default p[0] = pIntType; if (!FncJsVerifyIntParameter(p,1)) { return -11; } pIntType = p[0]; p[0] = pIntOptional; if (!FncJsVerifyIntParameter(p,1)) { return -11; } pIntOptional = p[0]; if (lStrFormatted == "") { if (pIntOptional == 0) { return -300; } return 0; } //Definindo o tipo do telefone switch(pIntType){ case 1: // Todos lStrRegExp = "^([^01789]\\d{1,3}|[789]\\d{2,3})(\\-)?\\d{4}$"; break; case 2: //fixo lStrRegExp = "^[^01789]\\d{1,3}(\-)?\\d{4}$"; break; case 3: //celular lStrRegExp = "^[789]\\d{2,3}(\\-)?\\d{4}$"; break; default: return -11; } lObjRegExp = new RegExp(lStrRegExp); if (!lObjRegExp.test(lStrFormatted)) { return -301; } pStrFormattedR[0] = lStrFormatted.replace("-",''); return 0; }