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

Character-based filters don't honor international characters #407

Closed
amireldor opened this issue Nov 20, 2016 · 5 comments
Closed

Character-based filters don't honor international characters #407

amireldor opened this issue Nov 20, 2016 · 5 comments
Milestone

Comments

@amireldor
Copy link

When trying the Dynamic Form Fields example, I entered some Hebrew characters on a field with the 'isAlphanumeric' filter but it did not validate. English characters were fine, but as soon as I added a Hebrew character the validation failed. The regex on the filter only checks for English letters and thus the validation fails. I believe this also fails on other international charachters, Thai, Chinese, Arabic, etc...

This is a bit tricky as JavaScript regexs are not UTF-8 friendly. There is a library called XRegExp which handles UTF-8 regexs but you don't want to add a library on top of your own library because that's funny. However, maybe you can "borrow" some code for detecting the international characters. I'm not sure, never dug into it too much, and it sounds funny as well.

In case anyone needs some Hebrew characters to copy paste and test: בהצלחה לכולם ויום הולדת שמח.

@aesopwolf
Copy link
Collaborator

This is a really good point, thanks for bringing it up. I've struggled with something similar when I wanted to allow emoji characters.

I think this can probably be solved in user land. We expose a validator called matchRegexp. And since the xregexp library on npm advertises that it compiles to native RegExp objects then in theory you can just pass pass the compiled regular expression to matchRegexp.

Let me know if that works for you or not.

@amireldor
Copy link
Author

It sounds as if it would work but I can't test that in a timely manner and get back here to report the results. If I do manage to get a project using formsy I will definitely try and let you know.

@aesopwolf
Copy link
Collaborator

I just gave it a quick test and it worked as expected! Didn't have to do anything special. For example:

<InputGroup
  name="emoji"
  label="emoji"
  type="text"
  validations={{
    matchRegexp: XRegExp('^\\pS$', 'A'), // https://github.com/slevithan/xregexp#unicode
  }}
  validationError="Please enter an emoji"
/>

I'll leave this open for now and close it once I add a note to our documentation.

@aesopwolf aesopwolf added this to the 0.20.0 milestone Dec 11, 2016
@amireldor
Copy link
Author

Good to know it worked, thanks.

@aesopwolf
Copy link
Collaborator

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

No branches or pull requests

2 participants