Can i limit the answer to certain format or no. of characters?

More
2 years 1 month ago #157690 by wendyt
Dear fellows,

I'd like to ask for mobile phone in numerical input/short free text but would like to limit (or validate) the response to 8 characters. I can only do it by setting maximum characters of 8 but this won't help to warn answers with fewer than 8 characters (digits).

Can it do this with "Validation"? If yes what shall i type there?

Thanks so much.

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
2 years 1 month ago - 2 years 1 month ago #157697 by Joffm
Hi, wendyt,

you can use regular expression for that.
See all these examples:
https://manual.limesurvey.org/Using_regular_expressions
Maybe the expression of your desired phone format is already there.

So, in your survey you are looking for exactly eight digits?
Start with "0" is allowed?
Something like:
/^[0-9]{8}$/
Not allowed:
/^[1-9][0-9]{7}$/

But read the manual about the use of the starting and trailing shlashes.

Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 years 1 month ago by Joffm.
The following user(s) said Thank You: LouisGac

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #157706 by Joffm
Hi, wendyt,

of course there is a second solution.

Use a numerical input, set minimum value to "10000000", maximun value to "99999999".

Okay, only works if leading "0" is not allowed.


And about the slashes in my first post. In validation you have to use them.

Best regards
Joffm


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

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #157713 by wendyt
Thank you very much Joffm. This manual is very useful and not sure why I didn't find it earlier.

Appreciate much :)

Cheers,
Wendy

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #157715 by wendyt
Hello Joffm,

I read over the manual but didn't tell how to do if I'd like to apply the validation equation into a sub-question. For example if i have a multiple short text question and asking for their name and mobile number, how shall i enter the validation equation into the "Sub-question validation equation"?

Thanks again for your help and sorry i am not familiar to scripts.

Best regards,
Wendy

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago - 2 years 1 month ago #157728 by Joffm
Hi, wendyt,
unfortunately you didn't mention this (multiple short text) in your first post.

There seems to be a bug in LS. Read https://www.limesurvey.org/forum/can-i-do-this-with-limesurvey/109810-multiple-short-text-regex-validation

So we have to find a different solution.

In "Sub-question validation equation:" enter: strlen(Q1_SQ003)==8 AND is_numeric(Q1_SQ003) AND substr(Q1_SQ003,0,1)!="0"
with Q1 = question code and SQ003 = subquestion code of the phone number.
I think you understand the meaning. The length of the string is 8 characters and it's numeric.
Add the blue part to avoid a leading "0".

In "Sub-question validation tip " you can enter something like "Please, enter exactly 8 digits in phone number"

Then you get (raw example screenshots)

Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 2 years 1 month ago by Joffm.
The following user(s) said Thank You: wendyt

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #157750 by wendyt
Appreciate much for your help Joffm. I need to set both short text and multiple short text for this validation and thanks so much for providing me the solution. Thanks again!

Please Log in or Create an account to join the conversation.

More
4 months 1 day ago #185522 by Mazi

wendyt wrote:

Dear fellows,

I'd like to ask for mobile phone in numerical input/short free text but would like to limit (or validate) the response to 8 characters. I can only do it by setting maximum characters of 8 but this won't help to warn answers with fewer than 8 characters (digits).


You can use the character count feature documented at How to count the number of characters entered at a Limesurvey text question to show the user a warning like "You have entered X of 8 characters".

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!