Regex validation rule not working as expected #3313

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

Projects

None yet

10 participants

@pareeohnos

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

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

I'm also having regex validation issues with dates.

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

@diuzzoli

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

@rishirebel

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
Iheff commented May 9, 2016

+1

@Iheff
Iheff commented May 11, 2016

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

@jlukic
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

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

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

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

@jlukic jlukic modified the milestone: 2.2, 2.2.x May 20, 2016
@jlukic
Member
jlukic commented May 20, 2016

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

@Iheff
Iheff commented May 20, 2016

Have you double escaped that?

Sent from my iPhone

On 20 May 2016, at 05:04, Frangeris Peguero notifications@github.com 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

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

@Iheff
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 notifications@github.com 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 milestone: 2.2, 2.2.1 Jun 26, 2016
@newswim
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
Member
jlukic commented Jul 31, 2016 edited

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 Jul 31, 2016
@jlukic jlukic added a commit that referenced this issue Jul 31, 2016
@jlukic jlukic #3313 remove logging 4d01914
@jlukic
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
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