Skip to main content
March 17, 2010
Answered

Check string for only Alpha characters

  • March 17, 2010
  • 1 reply
  • 6191 views

Is there a ColdFusion function that will check that a string has only alpha characters (not numeric or for example &,$, etc)? I'm trying to avoid creating a string of all alpha characters or all non-alpha characters to loop over and check against.

    This topic has been closed for replies.
    Correct answer ilssac

    That could easily be accomplished with a regular expression search using the REFIND() function.

    Something like this off the top of my head and untested example.  REFIND("[^A-Za-z]",yourStringVar).  If that returns true then there are characters other then alpha characters in the string.

    1 reply

    ilssac
    ilssacCorrect answer
    Inspiring
    March 17, 2010

    That could easily be accomplished with a regular expression search using the REFIND() function.

    Something like this off the top of my head and untested example.  REFIND("[^A-Za-z]",yourStringVar).  If that returns true then there are characters other then alpha characters in the string.

    March 17, 2010

    That does the trick. I was looking through the docs but could only manage to get to - REFind("[A-Za-z]",form.txt_firstname). Wasn't working but yours does, thanks.

    ilssac
    Inspiring
    March 17, 2010

    The difference is the carrot ^ character.  It is the regex not operator.  Your search [A-Za-z] was finding all the alpha characters, but that is what you want in your string.  Adding the ^ to get [^A-Za-z] is finding any character that is NOT an alpha character.