Repeat loop needed for automator variable input.

HI we have an automator workflow and I am trying to add some error handlers in applescript. This is so as to get the user to enter the correct information. It works but, if they entered it incorrectly again the variable would be set wrong. So i need to loop it until its correct.

Also how can i get it the script to distinguish between upper case and lowercase in the variable?

All works but I can’t get the repeat to work.
Please see below:

on run {input, parameters}
	set input to (input as text)
	if input contains " " = true then
		
		set input to display dialog "Please re-enter the Division Code using no spaces & no lowercase letters" default answer input
		set Input_DivCode to the text returned of the result
		
	else
		
		input contains " " = false
		set Input_DivCode to the text of the input
		
	end if
end run

Thanks for your help…

Hi All…
OK I have managed to get it to work… Although the searching for lowercase letters I am having difficulty with, so any advise would be grateful… Thanks…

on run {input, parameters}
	set input to (input as text)
	if input contains " " = false then
		set Input_DivCode to the input
	else
		repeat
			if input contains " " = true then
				
				display dialog "Please re-enter the Division Code using no spaces or lowercase letters" default answer input
				set input to the text returned of the result
				
				if input contains " " = false then exit repeat
			end if
		end repeat
		set Input_DivCode to the input
	end if
end run