Welcome, Guest
Username: Password: Remember me

TOPIC: help with text validation

help with text validation 2 years 6 months ago #74164

  • itsme
  • itsme's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 53
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74202

  • itsme
  • itsme's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 53
  • Thank you received: 1
  • Karma: 0
nobody have enough idea about validations? so what kind of valiations we are looking for online? regex validation?
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74213

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 248
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)limesurvey.org'"
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74263

  • itsme
  • itsme's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 53
  • Thank you received: 1
  • Karma: 0
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?
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74272

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 248
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)limesurvey.org'"
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74301

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4133
  • Thank you received: 763
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74338

  • itsme
  • itsme's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 53
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74398

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4133
  • Thank you received: 763
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74405

  • itsme
  • itsme's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 53
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: help with text validation 2 years 6 months ago #74410

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4133
  • Thank you received: 763
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.132 seconds
Donation Image