I would like to complement the answer by @Renan with a true CEP validation.
Although the Brazilian CEP is not defined by an algorithm itself but only one structured decimal representation of the country, like any logical structure it follows a standard Valizable by Regular Expressions.
Note that I wrote Regular Expressions, plural, as we have 26 States + one Federal District which, in one structure, result in 27 different patterns.
Years ago, when I was researching for CEP-based auto-fill alternatives, at a "time" when there weren’t many Webservices available and/or trusted, I ended up finding the database itself used by Correios for download in a blog that today no longer exists.
The important thing is that amid the article’s comments there was one of none other than Aurélio Marinho Jargas, author of the best reference book for Regular Expressions in Portuguese.
And in this particular comment he published these 27 Regular Expressions which I quickly tried to implement in PHP. Easy, easy, easy...
Despite the relative difficulty I had in porting the code to Javascript, I did, and leave it as a reference to the community in Jsfiddle.
After the basic length check, first the state is checked by a separate Regular Expression. Only then do we test the first five digits of the zip code, which are the ones that matter against the Regular Expression of the informed State.
All credit goes to Master Aurelius, I just packed everything up like a good Padawan. ^_^
I liked the comment: "brute force no, brute force!" kkkkkk +1 by the reply and comment
– Tafarel Chicotti
tou with @Tafarelchicotti, the comment is anything eheh
– Omni
It worked out, buddy, thanks!
– user7605
Renan, taking your tip, I have another similar problem. I have a string like this: str = "000.000.000". Which are values, how do I replace the digits, plus leaving the dots "." ?
– user7605
@user7605 Create another question with this question. Then more people will see, and you will have more space to detail the question ;)
– Oralista de Sistemas
Okay, I’m creating
– user7605