Yes, you can use substrigs to compare each letter of each string. The exact syntax will depend upon if the form is an Acrobat Form or LiveCycle Designer form and if LiveCycle Designer which scripting language.
There are a number of eSeminars on demand and articles about using Acrobat Forms and JavaScript that can help you learn how to perform various tasks in JavaScript.
George Kaiser