Jump to content
Fórum Script Brasil
  • 0

Regex


Edu Valente

Question

Boa tarde gente. Eu criei um padrão em regex para telefone só que eu gostaria que o test de p7 retorna-se false. Eu não sei escrever um padrão para invalidar p7 mantendo os outros (de p1 a p6) válidos . Obrigado pela ajuda.

var patternMatch = function()
{
    var p1 = "11111111";
    var p2 = "1111-1111";
    var p3 = "1111 1111";
    var p4 = "(21)11111111";
    var p5 = "(21)1111 1111";
    var p6 = "(21)1111-1111";
    var p7 = "(21)1111 -1111";
    
    document.write(/^(\d{4})|(\(\d{2}\)\d{4})(-{1}\d{4})|( ?\d{4})$/.test(p1) + "<br>");
    document.write(/^(\d{4})|(\(\d{2}\)\d{4})(-{1}\d{4})|( ?\d{4})$/.test(p2) + "<br>");
    document.write(/^(\d{4})|(\(\d{2}\)\d{4})(-{1}\d{4})|( ?\d{4})$/.test(p3) + "<br>");
    document.write(/^(\d{4})|(\(\d{2}\)\d{4})(-{1}\d{4})|( ?\d{4})$/.test(p4) + "<br>");
    document.write(/^(\d{4})|(\(\d{2}\)\d{4})(-{1}\d{4})|( ?\d{4})$/.test(p5) + "<br>");
    document.write(/^(\d{4})|(\(\d{2}\)\d{4})(-{1}\d{4})|( ?\d{4})$/.test(p6) + "<br>");
    document.write(/^(\d{4})|(\(\d{2}\)\d{4})(-{1}\d{4})|( ?\d{4})$/.test(p7) + "<br>");
}

window.onload = patternMatch;

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...