Search for lowercase letters in variable input.

Hi Im After a little help with getting this to work…

I need it to search the variable for lowercase letters… So if the input is ‘AFGH’ it reconises it as being OK as its uppercase but if the input was ‘afgh’ it would show the dialogue window again… I hope this makes sense.

on run {input, parameters}
	set input to (input as text)
	set uppercase to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	if characters of input is in uppercase then
		set Input_DivCode to the input
		
	else
		
		repeat
			if characters of input is not in uppercase 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 characters of input is in uppercase then exit repeat
			end if
		end repeat
		set Input_DivCode to the input
	end if
	
end run


Hi,

I recommend a silent lowercase conversion


on run {input, parameters}
	if class of input is list then set input to (item 1 of input)
	return do shell script "/bin/echo " & quoted form of input & " | /usr/bin/tr A-Z a-z"
end run


Try this…

set input to "ABcD"

set uppercase to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
repeat
	-- check each letter of the input against the uppercase letters
	set inputList to text items of input
	set allLettersAreUpperCase to true
	repeat with anInput in inputList
		considering case
			set isUpperCase to anInput is in uppercase
		end considering
		if not isUpperCase then
			set allLettersAreUpperCase to false
			exit repeat
		end if
	end repeat
	
	-- exit the repeat loop if all letters are uppercase else get new input
	if allLettersAreUpperCase then
		exit repeat
	else
		display dialog "Try again!" & return & return & "All letters must be UPPERCASE and there can be no spaces." default answer input
		set input to the text returned of the result
	end if
end repeat

-- all letters are upper case so do your stuff here!

A very Big thanks to both the suggestions…

StefanK What you did was good because it works without the input of the dialogue box…

regulus6633 That’s exactly what I was trying to do… But it’s obviously clear I wouldn’t of been able to
get anywhere near that…

So thank you both for your help…

Rob

2 things to note about StefanK’s code, 1) it’s actually backwards meaning it converts the input to lower case letters and 2) it doesn’t do anything about input with spaces, numbers, or other non-uppercase characters. To fix the backwards part (#1) you can change the one line to this…

return do shell script "/bin/echo " & quoted form of input & " | /usr/bin/tr a-z A-Z"

In general his idea is good but it may not be workable for your requirements considering the other characters you need to consider.