Added rule for brazilian postal code (CEP) #77

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
5 participants

xthiago commented Jul 3, 2012

I created a exception class for the brazilian CNPJ rule because this file doesn't exists in both branches (master and develop).

Besides that, I created a rule for brazilian postal code (CEP).

Owner

alganet commented Jul 3, 2012

Hi Thiago! Thanks for contributing =D

Could you provide tests for the Brazilian CEP validator? There is a guide here (https://gist.github.com/2356523), but if you need you can get in touch with me and I'll help you!

Also, I believe just "cep" is enough, previous cpf and cnpj validators didn't have the "brazillian" prefix. What do you think?

xthiago commented Jul 3, 2012

Hi Alexandre!

Yes, I can provide the tests. I will do at night. :D

I also think that cep() is much better, but postal code exists in most countries (unlike CPF and CNPJ). I guess that postalCode() may be is better. What do you think?

Do you suggest any way of specify the locale (as parameter, constant, etc) to postalCode()?

[1] http://en.wikipedia.org/wiki/Postal_code

Regards

Owner

alganet commented Jul 3, 2012

Could be something like v::postalCode('BR')->validate('09300-000');, Wikipedia already has a nice list of formats for several countries.

Thiago Rodrigues added some commits Jul 4, 2012

Thiago Rodrigues BrazilianCep*.php class refactored and renamed to PostalCode*.php. No…
…w is possible validate postal codes from others countries with v::postalCode(CC), where CC = Country Code (but only the Brazilian Postal Code has been implemented so far)
8ba4351
Thiago Rodrigues BrazilianCep*.php class refactored and renamed to PostalCode*.php. No…
…w is possible validate postal codes from others countries with v::postalCode(CC), where CC = Country Code (but only the Brazilian Postal Code has been implemented so far)
a6dad88
Thiago Rodrigues annotation about v::postalCode() added in Validation.php 5e922e5

xthiago commented Jul 4, 2012

Check out: https://github.com/xthiago/Validation/blob/develop/library/Respect/Validation/Rules/PostalCode.php

I will make the regex for other countries after write the unit tests. I'll do soon.

Owner

alganet commented Jul 19, 2012

Seems nice, @xthiago! Let me know if you need anything.

Member

nickl- commented Jan 9, 2013

Where are we with this, I cannot tell?

@xthiago can you please give a quick rundown of what you would like done here just to recap. The request cannot merge either so please do a rebase with upstream to correct that.

@alganet Did you have anything more to add?

Lets just all get on the same footing again and see what needs to be done to conclude this, agreed?

augustohp added this to the 0.6.0 milestone Feb 20, 2014

augustohp changed the title from Added rule for brazilian postal code (CEP) and exception class for CNPJ to Added rule for brazilian postal code (CEP) May 9, 2014

Owner

augustohp commented May 9, 2014

This needs more work until it can be merged:

  • Rebased against current master.
  • Point a new pull request towards master branch (I don't think one can change the target of a pull request after it is made).
  • Remove the missing CNPJfix form PR, already fixed on #151.

PS: The comments above are still pending.

@augustohp augustohp modified the milestone: Backlog, 0.6.0 May 9, 2014

@augustohp augustohp modified the milestone: 0.7.0, Backlog Jun 26, 2014

Owner

henriquemoody commented Jan 2, 2015

There is a awesome list in geonames.org with lots of zip codes validations, we just have to use Regex rule with that, check it out:

$ curl -L http://download.geonames.org/export/dump/countryInfo.txt |
     sed -E 's/^([A-Z]{2}).+(\^(.+)\$).*/    "\1" => "\2",/g' |
     grep '=>'

    "AD" => "^(?:AD)*(\d{3})$",
    "AM" => "^(\d{6})$",
    "AR" => "^([A-Z]\d{4}[A-Z]{3})$",
    "AT" => "^(\d{4})$",
    "AU" => "^(\d{4})$",
    "AX" => "^(?:FI)*(\d{5})$",
    "AZ" => "^(?:AZ)*(\d{4})$",
    "BA" => "^(\d{5})$",
    "BB" => "^(?:BB)*(\d{5})$",
    "BD" => "^(\d{4})$",
    "BE" => "^(\d{4})$",
    "BG" => "^(\d{4})$",
    "BH" => "^(\d{3}\d?)$",
    "BM" => "^([A-Z]{2}\d{2})$",
    "BN" => "^([A-Z]{2}\d{4})$",
    "BR" => "^(\d{8})$",
    "BY" => "^(\d{6})$",
    "CA" => "^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]) ?(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$",
    "CH" => "^(\d{4})$",
    "CL" => "^(\d{7})$",
    "CN" => "^(\d{6})$",
    "CR" => "^(\d{4})$",
    "CU" => "^(?:CP)*(\d{5})$",
    "CV" => "^(\d{4})$",
    "CX" => "^(\d{4})$",
    "CY" => "^(\d{4})$",
    "CZ" => "^(\d{5})$",
    "DE" => "^(\d{5})$",
    "DK" => "^(\d{4})$",
    "DO" => "^(\d{5})$",
    "DZ" => "^(\d{5})$",
    "EC" => "^([a-zA-Z]\d{4}[a-zA-Z])$",
    "EE" => "^(\d{5})$",
    "EG" => "^(\d{5})$",
    "ES" => "^(\d{5})$",
    "ET" => "^(\d{4})$",
    "FI" => "^(?:FI)*(\d{5})$",
    "FM" => "^(\d{5})$",
    "FO" => "^(?:FO)*(\d{3})$",
    "FR" => "^(\d{5})$",
    "GB" => "^(([A-Z]\d{2}[A-Z]{2})|([A-Z]\d{3}[A-Z]{2})|([A-Z]{2}\d{2}[A-Z]{2})|([A-Z]{2}\d{3}[A-Z]{2})|([A-Z]\d[A-Z]\d[A-Z]{2})|([A-Z]{2}\d[A-Z]\d[A-Z]{2})|(GIR0AA))$",
    "GE" => "^(\d{4})$",
    "GF" => "^((97|98)3\d{2})$",
    "GG" => "^(([A-Z]\d{2}[A-Z]{2})|([A-Z]\d{3}[A-Z]{2})|([A-Z]{2}\d{2}[A-Z]{2})|([A-Z]{2}\d{3}[A-Z]{2})|([A-Z]\d[A-Z]\d[A-Z]{2})|([A-Z]{2}\d[A-Z]\d[A-Z]{2})|(GIR0AA))$",
    "GL" => "^(\d{4})$",
    "GP" => "^((97|98)\d{3})$",
    "GR" => "^(\d{5})$",
    "GT" => "^(\d{5})$",
    "GU" => "^(969\d{2})$",
    "GW" => "^(\d{4})$",
    "HN" => "^([A-Z]{2}\d{4})$",
    "HR" => "^(?:HR)*(\d{5})$",
    "HT" => "^(?:HT)*(\d{4})$",
    "HU" => "^(\d{4})$",
    "ID" => "^(\d{5})$",
    "IL" => "^(\d{5})$",
    "IM" => "^(([A-Z]\d{2}[A-Z]{2})|([A-Z]\d{3}[A-Z]{2})|([A-Z]{2}\d{2}[A-Z]{2})|([A-Z]{2}\d{3}[A-Z]{2})|([A-Z]\d[A-Z]\d[A-Z]{2})|([A-Z]{2}\d[A-Z]\d[A-Z]{2})|(GIR0AA))$",
    "IN" => "^(\d{6})$",
    "IQ" => "^(\d{5})$",
    "IR" => "^(\d{10})$",
    "IS" => "^(\d{3})$",
    "IT" => "^(\d{5})$",
    "JE" => "^(([A-Z]\d{2}[A-Z]{2})|([A-Z]\d{3}[A-Z]{2})|([A-Z]{2}\d{2}[A-Z]{2})|([A-Z]{2}\d{3}[A-Z]{2})|([A-Z]\d[A-Z]\d[A-Z]{2})|([A-Z]{2}\d[A-Z]\d[A-Z]{2})|(GIR0AA))$",
    "JO" => "^(\d{5})$",
    "JP" => "^(\d{7})$",
    "KE" => "^(\d{5})$",
    "KG" => "^(\d{6})$",
    "KH" => "^(\d{5})$",
    "KP" => "^(\d{6})$",
    "KR" => "^(?:SEOUL)*(\d{6})$",
    "KW" => "^(\d{5})$",
    "KZ" => "^(\d{6})$",
    "LA" => "^(\d{5})$",
    "LB" => "^(\d{4}(\d{4})?)$",
    "LI" => "^(\d{4})$",
    "LK" => "^(\d{5})$",
    "LR" => "^(\d{4})$",
    "LS" => "^(\d{3})$",
    "LT" => "^(?:LT)*(\d{5})$",
    "LU" => "^(\d{4})$",
    "LV" => "^(?:LV)*(\d{4})$",
    "MA" => "^(\d{5})$",
    "MC" => "^(\d{5})$",
    "MD" => "^(?:MD)*(\d{4})$",
    "ME" => "^(\d{5})$",
    "MG" => "^(\d{3})$",
    "MK" => "^(\d{4})$",
    "MM" => "^(\d{5})$",
    "MN" => "^(\d{6})$",
    "MQ" => "^(\d{5})$",
    "MT" => "^([A-Z]{3}\d{2}\d?)$",
    "MV" => "^(\d{5})$",
    "MX" => "^(\d{5})$",
    "MY" => "^(\d{5})$",
    "MZ" => "^(\d{4})$",
    "NC" => "^(\d{5})$",
    "NE" => "^(\d{4})$",
    "NF" => "^(\d{4})$",
    "NG" => "^(\d{6})$",
    "NI" => "^(\d{7})$",
    "NL" => "^(\d{4}[A-Z]{2})$",
    "NO" => "^(\d{4})$",
    "NP" => "^(\d{5})$",
    "NZ" => "^(\d{4})$",
    "OM" => "^(\d{3})$",
    "PF" => "^((97|98)7\d{2})$",
    "PG" => "^(\d{3})$",
    "PH" => "^(\d{4})$",
    "PK" => "^(\d{5})$",
    "PL" => "^(\d{5})$",
    "PM" => "^(97500)$",
    "PR" => "^(\d{9})$",
    "PT" => "^(\d{7})$",
    "PW" => "^(96940)$",
    "PY" => "^(\d{4})$",
    "RE" => "^((97|98)(4|7|8)\d{2})$",
    "RO" => "^(\d{6})$",
    "RS" => "^(\d{6})$",
    "RU" => "^(\d{6})$",
    "SA" => "^(\d{5})$",
    "SD" => "^(\d{5})$",
    "SE" => "^(?:SE)*(\d{5})$",
    "SG" => "^(\d{6})$",
    "SH" => "^(STHL1ZZ)$",
    "SI" => "^(?:SI)*(\d{4})$",
    "SK" => "^(\d{5})$",
    "SM" => "^(4789\d)$",
    "SN" => "^(\d{5})$",
    "SO" => "^([A-Z]{2}\d{5})$",
    "SV" => "^(?:CP)*(\d{4})$",
    "SZ" => "^([A-Z]\d{3})$",
    "TC" => "^(TKCA 1ZZ)$",
    "TH" => "^(\d{5})$",
    "TJ" => "^(\d{6})$",
    "TM" => "^(\d{6})$",
    "TN" => "^(\d{4})$",
    "TR" => "^(\d{5})$",
    "TW" => "^(\d{5})$",
    "UA" => "^(\d{5})$",
    "US" => "^\d{5}(-\d{4})?$",
    "UY" => "^(\d{5})$",
    "UZ" => "^(\d{6})$",
    "VA" => "^(\d{5})$",
    "VE" => "^(\d{4})$",
    "VI" => "^\d{5}(-\d{4})?$",
    "VN" => "^(\d{6})$",
    "WF" => "^(986\d{2})$",
    "YT" => "^(\d{5})$",
    "ZA" => "^(\d{4})$",
    "ZM" => "^(\d{5})$",
    "CS" => "^(\d{5})$",

henriquemoody closed this in #226 Jan 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment