Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Check string for only Alpha characters

Guest
Mar 17, 2010 Mar 17, 2010

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.

6.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Mar 17, 2010 Mar 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.

Translate
Valorous Hero ,
Mar 17, 2010 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 17, 2010 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 17, 2010 Mar 17, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources