Welcome to the LimeSurvey Community Forum

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

Expressions régulières

More
8 years 11 months ago #119163 by cr80
Expressions régulières was created by cr80
Bonjour,

Je rencontre un souci avec les expressions régulières en validation d'un numéro de téléphone et un numéro de SIRET.

Je veux uniquement m'assurer qu'il n'y a que des chiffres et de la longueur de la chaîne est bien de 10 et 14 caractères.

N° de tél : j'utilise le regex suivant : /^\d{10}$/
Cela marche très bien si le premier chiffre n'est pas un 0. Dans le cas contraire je dois rajouter un chiffre de plus.

Pour le SIRET : /^\d{14}$/. Idem marche très sauf si l'on commence la chaine avec un zéro.

Est-ce un bogue ou une mauvaise utilisation de l’expression régulière ?

Vous remerciant par avance pour vos réponses ?

Bien à vous

English version :

Hello,

I am having trouble with regular expressions for validation a phone number and SIRET.

I want to ensure that the field is numeric and has well 10 and 14 characters .

Tel No : I am using the following regex / ^ \ d { 10} $ /
This works very well if the first digit is not 0. The Contrary Case I do not add more digit .

For SIRET / ^ d \ {14} $ / . Same walking very UNLESS the beginning on a channel with zero .

-this is a bug or a bad use Regular Expression ?

Thanking you in advance for your answers ?

Many greetings
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119181 by tpartner
Replied by tpartner on topic Expressions régulières
Yes, in my opinion, definitely a bug. Leading zeros are being ignored by Expression manager in numeric questions when the input value has more than one character. (I see the same with a short-text question set to "Numbers only")

Please file a bug report and...
  1. Give as much information as possible.
  2. Provide step-by-step instructions how to reproduce the problem.
  3. Provide screenshots and/or a sample survey.
  4. Post the link to the bug here so we can follow the progress.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: cr80
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago - 8 years 11 months ago #119215 by DenisChenu
Replied by DenisChenu on topic Expressions régulières

tpartner wrote: Yes, in my opinion, definitely a bug. Leading zeros are being ignored by Expression manager in numeric questions when the input value has more than one character. (I see the same with a short-text question set to "Numbers only")

Please file a bug report and...

  1. Give as much information as possible.
  2. Provide step-by-step instructions how to reproduce the problem.
  3. Provide screenshots and/or a sample survey.
  4. Post the link to the bug here so we can follow the progress.

In DB it saved like a number.

For numeric question type DECIMAL.

000 is a text, not a number: because 000==0

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 8 years 11 months ago by DenisChenu.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119220 by tpartner
Replied by tpartner on topic Expressions régulières
0123 IS a number!

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119226 by DenisChenu
Replied by DenisChenu on topic Expressions régulières
Maybe,

BUT :
regexp is apply to a string. If we have a number:

"001"*1 (in js) give 1 to string give "1".
and preg_match("\d{3}$","1") is false (even if 0001==1)

And more : here there are a concept issue.
Phone number don't have to be only number : +33 (0) 6 66 66 66 66 is a valid phone number
Same for siret : SIRET have 1 part : one SIREN + one NIC separate by a space (if user want).

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119227 by DenisChenu
Replied by DenisChenu on topic Expressions régulières
As number : preg_match ('/^[0-9]{2}$/',01) is false. Then no issue. Use Question text.

A plugin can be done to limit caracter

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119230 by tpartner
Replied by tpartner on topic Expressions régulières
Whatever. If you didn't read my comment "If the character is allowed to be input, the data should reflect EXACTLY what was input" in the bug I give up.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago - 8 years 11 months ago #119231 by DenisChenu
Replied by DenisChenu on topic Expressions régulières
In javascript : we can fix it in option
Code:
// (javascript) Send real value entered when using Numeric question type in Expression Manager : 0 : {NUMERIC} with bad caracters send '', 1 : {NUMERIC} send all caracters entered
$config['bNumRealValue']             = 0;

With DB (then with PHP): we can not fix it : value is save as DECIMAL(30,10) actually or float for Array number. And in PHP regexp is false.
Code:
preg_match ('/^[0-9]{2}$/",01)==false

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 8 years 11 months ago by DenisChenu.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose