Jump to content
Fórum Script Brasil
  • 0

Validar codigo postal com Jquery


m3io

Question

Boas malta precisa aqui de uma ajudinha pra saber onde estou falhando

jQuery.validator.addMethod("cod_postal", function(cod_postal, element) {
    return this.optional(element) || cod_postal.match(/(^\d{4}(-\d{3})?$)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnpstvxy]{1}\d{1}[A-Za-z]{1} ?\d{1}[A-Za-z]{1}\d{1})$/);
}, "Invalido codigo postal Formato xxxx-xxx");
<script type="text/javascript"> 
            $(document).ready( function() {
                $("#formularioContato").validate({
                    // Define as regras
                    rules:{
                        n_cliente:{
                            // campoNome será obrigatorio (required) e terá tamanho minimo (minLength)
                            required: true, minlength: 1,  maxlength: 5, digits: true
                        },
                        cod_postal:{
                           minlength: 3,
                            required: true
                        }
                    },
                    // Define as mensagens de erro para cada regra
                    messages:{
                        n_cliente:{
                            required: "O numero de cliente é obrigatório",
                            minlength: "Mínimo 1 caracteres",
                            maxlength: "Máximo 5 caracteres"
                        },
                        cod_postal:{
                            minlength: "Mínimo 4 caracteres"
                        },

    
                        campoMensagem:{
                            required: "Digite a sua mensagem",
                            minlength: "A sua mensagem deve conter, no mínimo, 2 caracteres"
                        }
                    }
                });
            });
        </script>
<form id="formularioContato">
<input  class="labelinput" name="cod_postal" type="text" value=""/>

</form>

alguém tem uma ideia de onde posso estar a falhar??

obrigado desde já :D

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...