Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Regex validation fails, but regex is valid

  • thompol
  • thompol's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago - 2 years 7 months ago #225394 by thompol
I'm hosting LimeSurvey (Version 5.2.9+220110) on my own server using the fruity theme.

I want to validate dutch mobile numbers that are written in a short text input. This is the RegEx i'm using as input validation:
Code:
^\(?([+]31)-?6(\s?|-)([0-9]\s{0,3}){8}$
On regex101.com, it works fine: regex101.com/r/qAdCZG/1

But when testing it in the survey preview, there's always a error displaying telling me to verify the input is correct.

I have tested different regular expressions but all have the same problem. Any idea what's going wrong here?

(and yes, I have left out the slashes as instructed in the manual )

Thanks in advance!
Last edit: 2 years 7 months ago by thompol. Reason: clarify

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #225395 by Joffm
Replied by Joffm on topic Regex validation fails, but regex is valid
Hi,
you entered the RegEx here?
 

Here you have to surreound by slashes.
This is not the condition editor.
In my opinion the phrase in the manual refers to the RegEx field in "Condition Designer"
 
Only as information.
You should not use this anymore. ExpressionScript is more flexible and powerful.

Joffm



 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • thompol
  • thompol's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #225397 by thompol
Replied by thompol on topic Regex validation fails, but regex is valid
Hi Joffm,

Thanks for your reply!

Indeed, that's where I'm adding it.

Sadly, adding the slashes doesn't fix it.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #225465 by Joffm
Replied by Joffm on topic Regex validation fails, but regex is valid
Hi, I do not see issues as long as there are hyphens included 





Without hyphens the regex fails.
 

Try to revise it.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #225476 by Joffm
Replied by Joffm on topic Regex validation fails, but regex is valid
And you can consider to use a mask.
Here with
[url] github.com/RobinHerbots/Inputmask [/url]
 
Enter this in the source code of the question (if it is a question of type "short text")
Code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/inputmask/4.0.9/jquery.inputmask.bundle.min.js"></script>
<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){ 
        $('#question{QID}  input[type="text"]').inputmask({
            'mask': '(+31) 6 99999999',
            'placeholder': '_',
            'removeMaskOnSubmit': false,
            'rightAlign': false,
        });
 
  });
</script>

Or the script from Igor Escobar
[url] igorescobar.github.io/jQuery-Mask-Plugin/docs.html [/url]
Here the placeholder
 

and the result
 

Using this script in the source code of the question
Code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.js"></script>
<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){ 
      
         $('#question{QID} input[type="text"]').mask('+31 6 00000000', { 
                placeholder: "+31 6 12345678" 
         });
    });
</script>

Adapt to your needs.
Just an idea

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
2 years 7 months ago - 2 years 7 months ago #225483 by DenisChenu
Replied by DenisChenu on topic Regex validation fails, but regex is valid

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 2 years 7 months ago by DenisChenu.

Please Log in to join the conversation.

  • thompol
  • thompol's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #225666 by thompol
Replied by thompol on topic Regex validation fails, but regex is valid
Seems like the hyphens were the problem, will test this to make sure. Weird that it did work in regex101 but not in LimeSurvey though.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose