I have a form within a modal, it serves for company registration. I'm trying to make the submit button stay disabled until the company's zip and cnpj are typed in the correct way. I've done a similar function for a login field, but I can not make it work here.
//faz o submit do cadastro de empressa ficar desabilitado no carregamento
$(document).ready(function() {
$('#btnCadastrarEmp').prop('disabled', true);
});
//faz o submit do cadastro de empresa ficar desabilitado se campo for incompativel com regex
$(document).keyup(function() {
if (! $('#empresaCep').val().match(/[0-9]{5}[-]?[0-9]{3}/) {
$(document).ready(function() {
$('#btnCadastrarEmp').prop('disabled', true);
});
}
}
//faz o submit do cadastro de empresa ficar habilitado se campo for compativel com regex
$(document).keyup(function() {
if ($('#empresaCep').val().match(/[0-9]{5}[-]?[0-9]{3}/) {
$(document).ready(function() {
$('#btnCadastrarEmp').prop('disabled', false);
});
}
}
When I put only the code to disable the submit, the page already loads with the blocked submit (like I want). But when I put the rest of the code to enable the submit if the value of the field is equal to the regex that I set, the error (the page already loads with the released submit). I do not know if the defect is in the regex or where, when I did this to validate a login form it worked. Besides that problem, does anyone know what a cnpj regex would look like? I've tried this: [0-9] {2}.? [0-9] {3}.? [0-9] {3} /? [0-9] {4} -? [0-9] 2}