Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Regex problem with / #63

Closed
eduardmartinez opened this issue Sep 3, 2015 · 4 comments
Closed

Regex problem with / #63

eduardmartinez opened this issue Sep 3, 2015 · 4 comments
Labels

Comments

@eduardmartinez
Copy link
Contributor

Hi. First at all thanks for this great package. It has saved my life.

Going right to the point, I was trying to use 'pattern' option to allow slashes but it throws an error and cuts the expression. For example:

<input type="text" id="mytext" name="mytext" validation="pattern=/^[0-9\s.\/()-+]+$/:alt=Error in expression" />

The error says:

Invalid regular expression: /^[0-9\s.\/: \ at end of pattern

I'm using backslash to escape slash into the expression. But the slash inside is cutting the expression and doesn't recognize the escaping.

Is there anyway to fix this, please? or In which way could I extend the service or something in order to add a new regular expression but without passing it as string?

Sorry for my bad english. Thanks in advance.

@ghiscoding
Copy link
Owner

Oh ok, it seems that my code is wrong and is pulling the code up to the first '/', I'll have to fix that.

@ghiscoding ghiscoding added the bug label Sep 4, 2015
ghiscoding added a commit that referenced this issue Sep 4, 2015
Custom Regex pattern was non-greedy and was causing problem when user
had a '/' inside his own custom pattern.
@ghiscoding
Copy link
Owner

Ok I fixed it, my own code was non-greedy and it was grabbing until it found the first '/' and that was the problem, so I just had to make it greedy and now it looks all fine. I only tried it via https://regex101.com/ and it seems fine now, see the print screen below.

If you still have an issue then let me know and I will re-open it, if need be...
Thanks for your feedback, enjoy my library and let everyone know about it :)

Before the fix, non-greedy, it stops at first '/' found
customregexbeforefix

After the fix, greedy, it stops at last '/' found
customregexafterfix

@eduardmartinez
Copy link
Contributor Author

Well, I already tested it and it seems to work like a charm. Thanks a lot! If anything goes wrong, I'll tell you. By the way, I noticed there are some words into Spanish language file (es.json) that are wrong or need some diacritical marks. If you want, I could help you with that and make you a pull request. ;)

@ghiscoding
Copy link
Owner

Oh yes go ahead and make a new pull request for the wrong Spanish words. Thanks for the feedback

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

No branches or pull requests

2 participants