Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostCode validator - regexp format and delimiters #18

Open
michalbundyra opened this issue Mar 15, 2020 · 0 comments
Open

PostCode validator - regexp format and delimiters #18

michalbundyra opened this issue Mar 15, 2020 · 0 comments
Labels
Bug Something isn't working

Comments

@michalbundyra
Copy link
Member

Bug Report

Q A
Version(s) 2.10.1 (current, and lower)

Summary

In PostCode we can provide any custom format. For example: AT-\d{4}
If we are not providing delimiters (/) with the regular expression it will be added inside:
/^AT-\d[4}$/ so we match the full string provided.

The problem is that we can provide regular expression with any delimiter, for example:
#^AT-\d{3}$# and it will be not detected correctly, so additional /^ and $/ will be added.

There might be a case also when adding /^ and $/ (with / delimiter) breaks the provided regular expression and other delimiter should be used.

Current behavior

We are attaching:

  • (prefix) /^ when first character of provided format is different than /
  • (suffix) $/ when the last character of provided format is different than /

See:

if ($format[0] !== '/') {
$format = '/^' . $format;
}
if ($format[strlen($format) - 1] !== '/') {
$format .= '$/';
}

How to reproduce

$validator = new PostCode(['format' => '#^AT-\d{3}$#']);
$validator->isValid('AT-123'); // should be true

Expected behavior

We should detect any delimiter used or noted clearly in the documentation that only one supported delimiter is /.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants