1
I have a form inside a modal, serves for registration of company. I’m trying to get the Ubmit button disabled until the company zip code and cnpj are typed in the correct way. I’ve done a similar function for a login field, but I can’t 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 only put the code to disable Submit, the page already loads with Submit locked (as I want). But when I put the rest of the code to enable Submit if the value of the field is equal to the regex I set, from the error ( the page already loads with the released Submit). I don’t know if the defect is in regex or where, when I did this to validate a login form worked. Beyond this problem, does anyone know what a regex of cnpj would look like? I tried this one: [0-9]{2}.? [0-9]{3}.? [0-9]{3}/? [0-9]{4}-? [0-9]{2}
About Regexp for CNPJ there are already other questions about this with good answers: https://answall.com/search?tab=votes&q=cnpj%20regex
– Sergio