0 votes

Suppose I want the user to enter a five-digit number as an answer to their question, but I need to validate that their answer has exactly 5 digits.

Is there a way to do so if I specify

*type: number

for that question?

by (5.8k points)

1 Answer

0 votes

Unfortunately, there is no built-in validation with predefined types in Guidedtrack. It is possible to write a custom check like this: https://www.guidedtrack.com/programs/13939

>> digits = "1234567890"
>> isValid = "yes"

*label: q

*if: isValid = "no"
	{raw_answer} is not a 5 digit number, try again!

*question: Enter 5 digit number, please
	*save: raw_answer

--validation logic begin


*if: not raw_answer.size = 5
	>> isValid = "no"
	*goto: q

>> i = 1
*while: i <= raw_answer.size
	>> isDidit = digits.find(raw_answer[i])
	*if: not isDidit
		>> isValid = "no"
		*goto: q
	>> i = i + 1
		
--validation logic end

Yay! {raw_answer} is valid!

 

by (5.8k points)
Welcome to Guidedtrack Q&A, where you can ask questions and receive answers from other members of the community.
134 questions
144 answers
55 comments
40 users