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

Regex validation rule not working as expected #3313

Closed
pareeohnos opened this issue Nov 11, 2015 · 18 comments
Closed

Regex validation rule not working as expected #3313

pareeohnos opened this issue Nov 11, 2015 · 18 comments

Comments

@pareeohnos
Copy link

I'm having an unusual issue with a regex validation rule. It seems to work in some cases, however I'm trying to use it to validate a date however it's saying that the date is not valid, even though it is.

http://jsfiddle.net/efp8z6Ln/260/

This fiddle shows an input field with a valid date value being validated using a regex. The regex itself works as demonstrated, and matches what it should, yet the form validation still returns false.

@jlukic jlukic added this to the 2.2.x milestone Nov 14, 2015
@elbouillon
Copy link

I'm also having an issue with regexp validation.

This regexp : regExp[/^+[0-9]{11}$/]
Don't validate +41791234567

I have that message in web console :
Uncaught SyntaxError: Invalid regular expression: /^+[0-9]{11}$/: Nothing to repeat

I think that your unvalid form is not due to your regexp but to semantic-ui form regexp rule handler

@douglasg14b
Copy link

I'm also having regex validation issues with dates.

https://jsfiddle.net/tL5xx6m9/2/

@diuzzoli
Copy link

Is there a solution to this issue?
I tried execute several RegExp with Semantic-ui form validation but always returns invalid field value.

@rishirebel
Copy link

Hi
I was trying to use RegExp /(19|20)\d\d//\s(0[1-9]|[12][0123])[:][1-6]\d/
for getting a date and time format like 1998/04/04 23:40, but it does not validate the same. I tested my RegExp several times on Regex testers, it works fine there, but it is not validating correctly on semantic ui

@Iheff
Copy link

Iheff commented May 9, 2016

+1

@Iheff
Copy link

Iheff commented May 11, 2016

Don't forget to double escape all the things. //d not /d for a digit for example.

@jlukic
Copy link
Member

jlukic commented May 15, 2016

Can someone give me a simple js regexp that is not evaluating correctly? I would love to fix

@elbouillon
Copy link

Hi @jlukic, I don't remember exactly, but the problem is not regex, but mixing short rules and complet rules. There is a thread mentionning that

@frangeris
Copy link

Having the same issue here, but with an string:

RegExp
regExp[/rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/i]

String
rgb(243, 243, 243)

Regular expression tested here...
https://regex101.com/r/gS7bD8/1

Where's the issue?

@frangeris
Copy link

@Iheff you're just right 👍 , for future references, I found the same solution here.

@jlukic jlukic modified the milestones: 2.2, 2.2.x May 20, 2016
@jlukic
Copy link
Member

jlukic commented May 20, 2016

I'll try to look over this as the last issues to put into 2.2

@Iheff
Copy link

Iheff commented May 20, 2016

Have you double escaped that?

Sent from my iPhone

On 20 May 2016, at 05:04, Frangeris Peguero [email protected] wrote:

Having the same issue here, but with an string:

RegExp
regExp[/rgb((\d{1,3}), (\d{1,3}), (\d{1,3}))/i]

String
rgb(243, 243, 243)

Regular expression tested here...
https://regex101.com/r/gS7bD8/1

Where's the issue?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@daltonamitchell
Copy link

I had a similar issue with date validation but double escaping fixed it. Is this mentioned anywhere in the docs?

@Iheff
Copy link

Iheff commented Jun 13, 2016

It is touched on, I think, although I cant find it for looking now. I think I googled my way to an answer* on it but thought it would be good to leave it somewhere further up the google trail.

  • [top answer on SO here: http://stackoverflow.com/questions/34684043/semantic-ui-regex-parser-does-not-seem-to-work-correctly]

You’d figure it out eventually though because it’s taking a string to pass a function that will run the regex so after a bit of head scratching it makes sense it should be re-escaped.

On 13 Jun 2016, at 20:00, Dalton A Mitchell [email protected] wrote:

I had a similar issue with date validation but double escaping fixed it. Is this mentioned anywhere in the docs?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #3313 (comment), or mute the thread https://github.com/notifications/unsubscribe/AA_qI3EDEo7XYWMOHOuhYS6OSp8K7wUeks5qLajigaJpZM4GgJDw.

@jlukic jlukic modified the milestones: 2.2, 2.2.1 Jun 26, 2016
@newswim
Copy link

newswim commented Jul 20, 2016

I was about to post an issue, having a hell of a time validating a phone number (which can be difficult in a lot of settings...)

DOUBLE ESCAPE special characters.

ex. \\d

thanks @Iheff

@jlukic
Copy link
Member

jlukic commented Jul 31, 2016

I've added a new syntax to make it simpler to pass in regular expressions

Instead of using bracketed notation, you can now pass in a value with a non stringified RegExp

$('.ui.form').form({
    fields: {
        color: {
          identifier: 'color',
          rules: [{
            type: 'regExp',
            value: /rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/i,
          }]
      }
    }
});

This is the only solution I could think of, as once the regexp is encoded as a string it is impossible to infer the original intention for escaped bracketing.

@jlukic jlukic closed this as completed Jul 31, 2016
jlukic added a commit that referenced this issue Jul 31, 2016
@jlukic
Copy link
Member

jlukic commented Jul 31, 2016

I've also added this specific example to usage section of form validatio to make it more clear.

@newswim
Copy link

newswim commented Jul 31, 2016

Thanks @jlukic !

I think this makes the validation a little more intuitive.

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

No branches or pull requests

10 participants