help with text validation

More
5 years 4 months ago #74164 by itsme
itsme created the topic: help with text validation
hello, as i am trying something in limesurvey, i was thinking to let user insert his username to continue the survey, cz it will be annoymous not to lock out any session with tokens, i have list of usernames such as user1 user2 user3 therefore i am thinking to make the first question as short-text and force them to put their username to conitnue... so how i can validate these usernames via validation in short-text type in the survey? i know about date, time and other stuff, but never used it for text,, any help is appreciated

Please Log in to join the conversation.

More
5 years 4 months ago #74202 by itsme
itsme replied the topic: help with text validation
nobody have enough idea about validations? so what kind of valiations we are looking for online? regex validation?

Please Log in to join the conversation.

More
5 years 4 months ago #74213 by Mazi
Mazi replied the topic: help with text validation
If you want to use the username a s a kind of password, you have to store it somewhere, e.g. at the tokens table. For then checking if the answer to the inital text question matches the token value, you can use conditions but your survey has to be non anonymous.

If you just want to check the syntax of a username and need no real string matching, you can use regular expressions: docs.limesurvey.org/Using+regular+expres...tions+for+LimeSurvey


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 4 months ago #74263 by itsme
itsme replied the topic: help with text validation
yes thats what i mean, thanks Mazi, only text string, no matching nor tockens are required.

problem is everyone is explaining how to use custom codes for email validation or email validations, but nobody speaks about normal username or string...

so if i have 5users like user1 user2 user3 user4 user5 what the code could look like?

Please Log in to join the conversation.

More
5 years 4 months ago #74272 by Mazi
Mazi replied the topic: help with text validation

itsme wrote: so if i have 5users like user1 user2 user3 user4 user5 what the code could look like?

I'm no regular expression expert but there are several forums and regex testers for that and Google might also help.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 4 months ago #74301 by tpartner
tpartner replied the topic: help with text validation
I think rather than trying to use regexes, it may be easier to use JavaScript to disable the "Next" button and validate the text input against a list of passwords (either hard-coded or imported from CSV).

Here's a similar thread disabling the "Next" button - www.limesurvey.org/en/forum/can-i-do-thi...from-advancing#74133

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 4 months ago #74338 by itsme
itsme replied the topic: help with text validation
thanks for the reply dude, appreciated. Actually i need the written value to be stored in the DB with the survey results.. this way it will store only yes and no!? so regexes i think it will serve this purpose better? or any other method that i can validate a text of 6 or 7 individual words that they to be typed by user as confirmation of his username and same not allowing him to continue unless he is one of that names?! just trying this is stronger than listing them into a drop-down list! obviously! so hint regarding the same is appreciated.

thanks in advanced

Please Log in to join the conversation.

More
5 years 4 months ago #74398 by tpartner
tpartner replied the topic: help with text validation
No problem dude.

My suggestion was not to follow the linked thread exactly but to use that method of disabling the Next button until a text input was validated by JavaScript. But I suppose you could do it with regular expressions...

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 4 months ago #74405 by itsme
itsme replied the topic: help with text validation
exactly, any idea about how to validate exact string? or at least what kind of validation is used in here to google it? google pumps huge information about different programming languages using different methods of validations!

any help with this will be appreciated

Please Log in to join the conversation.

More
5 years 4 months ago #74410 by tpartner
tpartner replied the topic: help with text validation
1) Set up your survey to use JavaScript .

2) Add the following script to the source of the short-text question. Replace "QQ" with the short-text question ID and modify the usernames as required.

The script disables the "Next" button and puts a listener on the short-text input. If a valid input is detected, the "Next" button is enabled, otherwise an alert is popped up.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
		var qID  = QQ;
		var usernames = ['user1','user2','user3','user4'];
		var msg = 'That is an incorrect username.';
 
		// Disable the next button
		$('#movenextbtn').attr('disabled', true);
 
		// A listener on the text input
		$('#question'+qID+' input.text').change(function(){ 
			var validVal = 0;
			var inputVal = $(this).val();
 
			// Loop through the usernames and test the input value
			$(usernames).each(function(i){
				if(inputVal == this) { // If a match is found...
					validVal = 1;
				}
			});
 
			// Act depending on whether a valid username was entered
			if(validVal == 1) { // A valid input
				$('#movenextbtn').attr('disabled', false);
			}
			else { // An invalid input
				$('#movenextbtn').attr('disabled', true);
				alert (msg);
			}
		});
 
 
    });
 
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now