Validate Some Fields #js #jquery #validate
jQuery(window).on('load', function(){
$('#cred_user_form_21174_1').on('submit', function(event) {
var data_telefone = $('[name="wpcf-telefone"]').val();
var data_celular = $('[name="wpcf-celular"]').val();
var data_cnpj = $('[name="wpcf-cnpj"]').val();
var data_ie = $('[name="wpcf-ie-rg"]').val();
var data_cep = $('[name="wpcf-cep"]').val();
var telefone_proibidos = [
"(11) 1111-1111",
"(22) 2222-2222",
"(33) 3333-3333",
"(44) 4444-4444",
"(55) 5555-5555",
"(66) 6666-6666",
"(77) 7777-7777",
"(88) 8888-8888",
"(99) 9999-9999",
"(00) 0000-0000"
];
var celular_proibidos = [
"(11) 11111-1111",
"(22) 22222-2222",
"(33) 33333-3333",
"(44) 44444-4444",
"(55) 55555-5555",
"(66) 66666-6666",
"(77) 77777-7777",
"(88) 88888-8888",
"(99) 99999-9999",
"(00) 00000-0000"
];
var cnpj_proibidos = [
"11.111.111/1111-11",
"22.222.222/2222-22",
"33.333.333/3333-33",
"44.444.444/4444-44",
"55.555.555/5555-55",
"66.666.666/6666-66",
"77.777.777/7777-77",
"88.888.888/8888-88",
"99.999.999/9999-99",
"00.000.000/0000-00",
"12.345.678/9012-34",
"11.223.344/5566-77"
];
var ie_proibidas = [
"111.111.111.111",
"222.222.222.222",
"333.333.333.333",
"444.444.444.444",
"555.555.555.555",
"666.666.666.666",
"777.777.777.777",
"888.888.888.888",
"999.999.999.999",
"000.000.000.000",
"123.456.789.000",
"112.233.445.566",
"111.222.333.444"
];
var cep_proibidos = [
"11111-111",
"22222-222",
"33333-333",
"44444-444",
"55555-555",
"66666-666",
"77777-777",
"88888-888",
"99999-999",
"00000-000",
];
var bad_telefone = telefone_proibidos.indexOf(data_telefone);
var bad_celular = celular_proibidos.indexOf(data_celular);
var bad_cnpj = cnpj_proibidos.indexOf(data_cnpj);
var bad_ie = ie_proibidas.indexOf(data_ie);
var bad_cep = cep_proibidos.indexOf(data_cep);
if(data_telefone == "" || bad_telefone != -1){
erro_telefone = 1;
$('[name="wpcf-telefone"]')
.css("border-color", "#D00")
.css("background", "#fbe4e4")
.effect("shake");
}
else {
erro_telefone = 0;
$('[name="wpcf-telefone"]')
.css("border-color", "#d9d9d9")
.css("background", "#f2f2f2");
}
if(data_celular == "" || bad_celular != -1){
erro_celular = 1;
$('[name="wpcf-celular"]')
.css("border-color", "#D00")
.css("background", "#fbe4e4")
.effect("shake");
}
else {
erro_celular = 0;
$('[name="wpcf-celular"]')
.css("border-color", "#d9d9d9")
.css("background", "#f2f2f2");
}
if(data_cnpj == "" || bad_cnpj != -1){
erro_cnpj = 1;
$('[name="wpcf-cnpj"]')
.css("border-color", "#D00")
.css("background", "#fbe4e4")
.effect("shake");
}
else {
erro_cnpj = 0;
$('[name="wpcf-cnpj"]')
.css("border-color", "#d9d9d9")
.css("background", "#f2f2f2");
}
if (data_ie == "" || bad_ie != -1) {
erro_ie = 1;
$('[name="wpcf-ie-rg"]')
.css("border-color", "#D00")
.css("background", "#fbe4e4")
.effect("shake");
}
else {
erro_ie = 0;
$('[name="wpcf-ie-rg"]')
.css("border-color", "#d9d9d9")
.css("background", "#f2f2f2");
}
if(data_cep == "" || bad_cep != -1){
erro_cep = 1;
$('[name="wpcf-cep"]')
.css("border-color", "#D00")
.css("background", "#fbe4e4")
.effect("shake");
}
else {
erro_cep = 0;
$('[name="wpcf-cep"]')
.css("border-color", "#d9d9d9")
.css("background", "#f2f2f2");
}
if(erro_telefone !== 0 || erro_celular !== 0 || erro_cnpj !== 0 || erro_ie !== 0 || erro_cep !== 0) {
event.preventDefault();
}
});
});