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

Assert::alpha() only works with Latin characters #98

Closed
rossbearman opened this issue Apr 4, 2019 · 4 comments · Fixed by #112
Closed

Assert::alpha() only works with Latin characters #98

rossbearman opened this issue Apr 4, 2019 · 4 comments · Fixed by #112

Comments

@rossbearman
Copy link
Contributor

Because of the reliance on ctype_alpha, in most locales Unicode characters will be rejected, despite being very common in strings that you might want to check only contain letters.

It would be great to see a new assertion that accepts common letters like Å or Ö. Perhaps using the regex /^\p{L}*$/ would be most appropriate?

\p{L} will match any valid Unicode letters, in either case.

@pablothedude
Copy link

pablothedude commented Jun 7, 2019

Confirmed, but should the validation also pass with Chinese characters and be independent of the active locale? As this will going to happen after the suggested change?

@BackEndTea
Copy link
Collaborator

Thank you for opening this issue.

Currently, the locale is 'forced', so the ctype based asserts are independent of locale.

If this new assertion gets added, what do you think it should be named?
And how should it handle other cases like Chinese characters as @pablothedude mentioned?

I'd also like to point out that the regex you linked may not work as intended: https://3v4l.org/7M1LZ

@rossbearman
Copy link
Contributor Author

Ah, the regex will need the u flag in order to enable PHP's Unicode support.

See: https://3v4l.org/sW6Z8

The name Assert::letter() would probably be most appropriate, as it is checking against Unicode's letter character class. As such, supporting Chinese letters would be consistent and clear.

@BackEndTea
Copy link
Collaborator

Ah, the regex will need the u flag in order to enable PHP's Unicode support.

Guess i missed that, it does look more promising now. I think this fits a common enough use case to add this to the libary, so feel free to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants