How would I validate this pattern: 2 digits followed by last name, basically any length of letters. Apple script does not use regular expressions, correct?
I need to validate user input and all student user IDs on my campus are in that format.
repeat
display dialog "Enter user name: (like 99smith)" default answer "" giving up after 40
set {userName, returnedButton, gaveupBoolean} to the result as list
-->{"some text", "OK", false}
if userName is not "" then
set CheckName to text 1 thru 2 of userName & " --test"
display dialog CheckName & " -- 1"
if class of CheckName is number then
display dialog CheckName & " -- 2"
exit repeat
else
display dialog "Name does not start with 2 digits " & CheckName & " -- " & userName
end if
end if
end repeat
Best Answer
Can you approach it like this:
Take the first two characters:
--test to see if they are numbers.
-->If not return invalid.
Take the remaining characters:
--test for minimum length?
--> if not return invalid.
--test each character to see if they are numbers.
--> If any character is a number return invalid.
Edit to add:
Rather than checking to see if
CheckName
is a number try converting it to a number: