Semantic-ui: Regex validation rule not working as expected

Created on 11 Nov 2015  ·  18Comments  ·  Source: Semantic-Org/Semantic-UI

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.

Evaluating Bug / Change

Most helpful comment

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

All 18 comments

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

I'm also having regex validation issues with dates.

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

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

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

+1

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

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

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

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?

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

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

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

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

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.

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 https://github.com/Semantic-Org/Semantic-UI/issues/3313#issuecomment-225675755, or mute the thread https://github.com/notifications/unsubscribe/AA_qI3EDEo7XYWMOHOuhYS6OSp8K7wUeks5qLajigaJpZM4GgJDw.

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

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.

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

Thanks @jlukic !

I think this makes the validation a little more intuitive.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iPaoo picture iPaoo  ·  3Comments

ghost picture ghost  ·  3Comments

ghost picture ghost  ·  3Comments

Morrolan picture Morrolan  ·  3Comments

zhaoyao91 picture zhaoyao91  ·  3Comments