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

More
4 months 13 hours ago #157690 by wendyt
wendyt created the topic: Can i limit the answer to certain format or no. of characters?
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 to join the conversation.

More
4 months 12 hours ago - 4 months 12 hours ago #157697 by Joffm
Joffm replied the topic: Can i limit the answer to certain format or no. of characters?
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
Last Edit: 4 months 12 hours ago by Joffm.
The following user(s) said Thank You: LouisGac

Please Log in to join the conversation.

More
4 months 9 hours ago #157706 by Joffm
Joffm replied the topic: Can i limit the answer to certain format or no. of characters?
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

Please Log in to join the conversation.

More
3 months 4 weeks ago #157713 by wendyt
wendyt replied the topic: Can i limit the answer to certain format or no. of characters?
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 to join the conversation.

More
3 months 4 weeks ago #157715 by wendyt
wendyt replied the topic: Can i limit the answer to certain format or no. of characters?
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 to join the conversation.

More
3 months 4 weeks ago - 3 months 4 weeks ago #157728 by Joffm
Joffm replied the topic: Can i limit the answer to certain format or no. of characters?
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
Attachments:
Last Edit: 3 months 4 weeks ago by Joffm.
The following user(s) said Thank You: wendyt

Please Log in to join the conversation.

More
3 months 3 weeks ago #157750 by wendyt
wendyt replied the topic: Can i limit the answer to certain format or no. of characters?
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 to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!