validate employee code from a text file

Hi All,
Please look into this script, where I am making mistake.


tell application "Finder"
	
	set EMP_CODE to text returned of (display dialog "Please enter your code" default answer "XXX") as string
	
	if EMP_CODE is not string then
		display dialog "Invalid Code Entered"
	end if
end tell

I want to chek if user will input any interger type value, it give three try and after three try, program should terminated automatically.

One more think I would like to do:

There is a file named “EMP_CODE.TXT”, which contains employee code. As user will enter code, it will search in this text file and if the code does not exist then it shows a dialog box “You are not a valid user”.

The “EMP_CODE.TXT” is a my startup disk.

Thanks
Rajeev

Hi Rajeev,

assuming your list of codes has one code per line and the line endings are UNIX style, something like this script should work:

property pathToEMP : ".../path/to/EMP_CODE.TXT" -- replace this with the UNIX (POSIX) path to your EMP_CODE.TXT file
set cnt to 0

repeat while (cnt < 3)
	set EMP_CODE to text returned of (display dialog "Please enter your code (" & (3 - cnt) & " tries left)" default answer "XXX")
	try
		do shell script ("cat " & pathToEMP & " | grep -e ^" & EMP_CODE & "$")
		exit repeat
	on error
		set cnt to cnt + 1
	end try
end repeat

if cnt = 3 then quit

display dialog "you made it"

D.

And one more note, Rajeev: You didn’t need the Finder which is only required for things that it does.