Commit graph

840 commits

Author SHA1 Message Date
Brian Johnson f8c90fa368
Fix Regex for Canadian postal code
Removes the errant space in the CA PostalCode regex.
This space was introduced by 5a067fa.

It also adds unit tests for the CA PostalCode to validate
the fix.

Reviewed-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-11-04 22:58:45 +01:00
ong-ar 892b39e5ff
Update Korean postal code validation
The Korea Postal code system changed from a 6-digit postal code system
to a 5-digit postal code system on August 1, 2015 [1] [2].

This commit makes sure that the "PostalCode" rule validates Korean
postal codes correctly.

[1]: http://www.fedex.com/ky/koreapostalcode/index.html
[2]: http://www.epost.go.kr/roadAreaCdEng.retrieveLnEngAreaCdList.comm

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-10 20:51:31 +02:00
Henrique Moody 203f8e7e9d
Update TLD list with version 2018100800 from IANA
As it seems, the TLDs "goodhands", "jlc", "panerai", "statoil",
"telecity", and "vista" were removed from the list.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-09 06:03:51 +02:00
Konstantin c9850f4ec7
Make sure that "Email" only validates strings
There shouldn't be possible to consider a non-string value as a valid
email anyways, but the real problem is that the "RFCValidation" from
"egulias/email-validator" casts the input as a string which makes PHP
trigger an error.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-09 05:28:51 +02:00
Henrique Moody 5a067faec7
Update "PostalCode" list
Updated the whole list according to the last version found on
geonames.org.

The script that I executed to generate the list is:

curl -L http://download.geonames.org/export/dump/countryInfo.txt |
  sed 's,\t,\;,g' |
  sort -u |
  cut -d ';' -f 1,15 |
  sed -E "/^#/d; /^[A-Z]{2}\;$/d; s,([A-Z]{2})\;(.+),'\1' => '/\2/'\,,g"

After generating the list I few changes had to be made since some of the
postal codes in the list were manually updated because they were not
correct.

This change was made because James Macon reported that "110231" was
not recognized as a valid Colombian postal code.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-29 22:30:50 +02:00
Henrique Moody a039d6d4b9
Fix wrong behavior of "Date" rule
The validation was considering "99" as a valid month and neither
date_parse_from_format() [1] or DateTime::createFromFormat() [2] would
complain about that.

The solution for that was to use checkdate() [3] to verify whether the
date is valid or not. Also, an extra step was added to the validation
that a date that only contains a day would return false since a day
without a month and year is impossible to validate.

Apparently, there is no problem while validation when it comes to time,
therefore nothing needed to be added for this validation.

[1]: http://php.net/date_parse_from_format
[2]: http://php.net/datetime.createFromFormat
[3]: http://php.net/checkdate

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-29 21:46:53 +02:00
Henrique Moody add542ea48
Update "Tld" rule with IANA's list
This commit will update the list of Top-Level Domains in the "Tld" rule
with the latest version found in the website of IANA (Internet Assigned
Numbers Authority).

The list was created with the commands below:

curl -L curl -L https://data.iana.org/TLD/tlds-alpha-by-domain.txt |
    grep -v '^#' |
    tr '[A-Z]' '[a-z]' |
    sed -E "s,^,',; s/$/', /" |
    tr -d '\n' |
    fold -w 72 -s

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-18 15:10:37 +02:00
Andrei Drulchenko 19d6ec8939 fix IntVal() leading zero behavior 2018-08-01 16:06:54 +03:00
Henrique Moody 47f21596a5
Fix casting error in AbstractInterval classes
The classes that are children of "AbstractInterval" convert their values
before comparing them.

Because PHP tries to convert values when making comparisons and an
"DateTime" object cannot be converted to integer or float some
validations would result into PHP triggering an error like:

> Object of class DateTime could not be converted to int
> Object of class DateTime could not be converted to float

This commit prevents that to happen by verifying if both compared values
are scalar or not before comparing them with each other.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-28 05:01:58 +02:00
Axel Wargnier 4f3aa90d1f Fix postalCode for Portugal (PT) 2018-07-25 12:33:08 +02:00
Henrique Moody 667ed36b48
Fix grammatical errors in URL exception message
Although the "U" at the first of URL is a vowel, the abbreviation is
pronounced "you-are-ell". Because the letter "Y" is a consonant in this
case, we should use "a" instead of "an".

Link: https://itknowledgeexchange.techtarget.com/writing-for-business/which-is-correct-a-url-or-an-url/

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-02 08:22:41 +02:00
Wojciech Frącz 83bb6e3fc9
Fix wrong behavior when using templates
When a template is set for a chain of rules, does not really matter
which messages the chain can have, the only message to be used should be
the one based on the defined template.

This commit set the same template of a parent rule to its children's
exception. Our first thought was to set the template to its children
however that would mean that if another rule would be added to the chain
we would have to set it as well. Doing that to the children's exception
make sure we only do that once.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-02 07:57:21 +02:00
Sebastian 8fc2484428
Fix postal code for The Netherlands
Postal code for NL allows for a space between the digits and the
letters.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-29 01:10:31 +01:00
Henrique Moody 4fdd2da19e
Fix wrong behavior with nested exceptions
Use the same condition to not include child exception into the iterator
to also not show the message of the main exception when using
"getFullMessage()".

The method created to validate that condition should probably be in the
"ValidationException" itself, but this commit is meant to be a bug fix,
which will be released in a PATH version, and creating this public
method would imply that a MINOR version should be released.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-29 00:50:27 +01:00
Adam Benson f5ca4a298a
Fix "IntVal" considering boolean values as valid
The commit 54d17ab tried to fix the that "IntVal" would pass with values
that are not considered as an integer, but it does not change

Even thought the commit 54d17ab fixes part of the wrong behaviour it
left out the filter for boolean values.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-28 22:09:42 +01:00
Henrique Moody 54d17abcee
Do not consider any float as integer
Values like "500.00" or 1.0 should not be considered as integer values
even though there is no data loss when they're converted to integer.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-23 21:15:38 +02:00
Henrique Moody 0e73bc732e
Avoid using unset keys in IpException
The "IpException" was triggering an error when the parameters
"networkRange" or "min" were not defined.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-23 21:00:04 +02:00
Radoslaw Wesolowski 700e23777f
Added .studio tld
https://icannwiki.org/.studio
2018-06-06 14:57:39 +02:00
Tim Bond 020ea1ebb5
Update type parameters for Validator doc blocks
The "@param" tag uses phpdoc types. However the "@method" tag uses PHP's
type declarations. Therefore, "mixed" refers to a class whose literal
name is mixed and not the "mixed" keyword. Since "mixed" is not a valid
class name in this context, the type paramaters should be removed.

Additionally, the "callable" type paramater can be used on the
"callback" validation method.

References:
[1]: http://docs.phpdoc.org/references/phpdoc/tags/param.html
[2]: http://docs.phpdoc.org/references/phpdoc/types.html
[3]: http://docs.phpdoc.org/references/phpdoc/tags/method.html
[4]: http://php.net/functions.arguments#functions.arguments.type-declaration
[5]: http://docs.phpdoc.org/references/phpdoc/types.html
Reviewed-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-19 16:26:44 +02:00
Tim Bond 4c996258a1
Update NestedValidationException doc block 2018-05-19 16:19:16 +02:00
MacFJA df985765a6
Update French subdivision codes 2018-05-19 16:18:28 +02:00
Henrique Moody ee9e69776a
Merge branch '1.0' into 1.1 2018-01-02 22:47:22 +01:00
Henrique Moody c931e2504b
Change conditions for Domain validation
Domains can have `--` as long as they don't start or end with `-` in its
parts.
2018-01-02 22:24:43 +01:00
Henrique Moody 37a71de7d0
Try to find template from default templates first
When executing `ValidationException::setTemplate()` using a template
key, it does not try to select the template, but instead it uses the
template key as the template itself.

In order to fix this behaviour, there is now a check for a key with the
defined template. In case the template was not found, use the defined
template as the template itself.
2018-01-02 21:56:07 +01:00
Henrique Moody 22f1f14430
Merge branch '1.0' into 1.1 2017-10-17 12:15:51 +02:00
Henrique Moody 14572537fe
Improve "Phone" rule
- Only allow spaces and not "\t" or "\n";
- Once the number has a "(", it needs a ")".
2017-10-17 09:51:09 +02:00
RCooLeR 191ee47fc0
Update regex of "Phone" rule
Now regex also matches +1 (555) 555 5555
2017-10-17 08:58:47 +02:00
Henrique Moody 631affdbf2
Merge branch '1.0' into 1.1 2017-10-16 10:39:15 +02:00
Tim Strijdhorst c013fac277
Fix currency code for Belarusian Ruble
References:
- https://en.wikipedia.org/wiki/ISO_4217
- http://www.xe.com/iso4217.php
2017-10-16 10:16:47 +02:00
Jonathan Stewmon 298102ba13 Use annotations for variadic methods 2017-03-27 13:37:47 +02:00
Henrique Moody 5ab87d1dd9
Merge branch '1.0' into 1.1 2017-03-14 10:44:11 +01:00
Henrique Moody dc869ac375
Only return "name" as is if it's a string 2017-03-14 10:28:03 +01:00
Henrique Moody 03f4abbd08
Merge branch '1.0' into 1.1 2017-01-26 15:39:48 +01:00
Yosmany Garcia 8eb95c2b04
Updated provinces of Cuba
Updated provinces of Cuba according to the change of 2011
2017-01-26 15:38:38 +01:00
Michał Prochowski fa61315079
Czech and slovakia postal code patterns fix. 2017-01-26 15:37:37 +01:00
Renato Moura e4ae02fe94
Fix "Cnpj" rule 2017-01-25 17:41:21 +01:00
Henrique Moody 710e807a68
Merge branch '1.0' into 1.1 2016-10-29 15:29:17 +02:00
Henrique Moody f82fcf0762
Prevent "Regex" to process non-string inputs 2016-10-29 15:21:14 +02:00
Henrique Moody bd636cc75e
Add support for "egulias/email-validator" 2.x 2016-10-29 15:20:13 +02:00
Henrique Moody e457f19dbd
Merge branch '1.0' into 1.1 2016-09-20 08:44:39 +02:00
Henrique Moody 98050476c6
Always return a valid exception
If calling the method `getExceptionForPath()` when the exception was
nested but had no child it was returning null. This commit ensures that
it always return a valid exception.
2016-09-19 18:22:39 +02:00
Henrique Moody 3fa5bc0489
Merge branch '1.0' into 1.1 2016-09-19 11:24:33 +02:00
Emmerson d0a98ae5d3
Date rule accepting scalar and DateTimeInterface 2016-09-19 10:13:01 +02:00
Henrique Moody c79d8fdf4f
Change file mode of "Image" rule 2016-09-19 09:32:42 +02:00
Gabriel Pedro a772d7f89a
Replace CNH validation algorithm
The old algorithm not working with some CNH values, e.g 00641829409.

You can even do some checking on
http://www.detran.pr.gov.br/modules/catasg/servicos-detalhes.php?tema=motorista&id=239.

Original algo can be found on
http://forum.imasters.com.br/topic/400293-validate-br.
2016-09-18 13:25:18 +02:00
Henrique Moody edf4e49ac6
Merge branch '1.0' into 1.1 2016-09-17 21:30:00 +02:00
Henrique Moody 4bcc4027f8
Try to use the getRelatedByName() method first
Then using the `findMessages()` method, tries to use the method
`getRelatedByName()` before using the `findRelated()` method.

This change was made because since on `KeyNested` rule you may have
names with '.' we'll never get the proper exception using
`findRelated()`.
2016-09-17 21:11:55 +02:00
Henrique Moody 98443bad0c
Get the proper exception when using findMessage() 2016-09-17 21:04:24 +02:00
Henrique Moody 494b67871f
Fix wrong behaviour on AbstractRelated
When you define the name for an `AbstractRelated` instance, you expect
that it also define the name for its child. But, when the child already
had a name the `AbstractRelated` was overwriting its name with the
`reference`.
2016-09-17 20:23:38 +02:00
Henrique Moody 6d0e3a2422
Merge branch '1.0' into 1.1 2016-09-13 11:32:43 +02:00