Dexterity: Checking for Special Characters in a String

David Meego - Click for blog homepageToday, I responded on a Partner Forum thread about evaluating the contents of a string field. The question was:

Is there a function that evaluates a string field to determine if it contains any special characters?

I have written similar code in the past and decided to quickly create a function to perform two functions:

  1. Return a Boolean to indicate if a special character has been found
  2. Pass out a string containing only the normal (non-special) characters

This function identifies alphabetic (optionally including space) and numeric characters as normal and anything else as “special”.

Global Function: IsSpecial

function returns boolean OUT_Special;
in string IN_String;
in boolean IN_SpaceAllowed;
out string OUT_Stripped;

local string l_char;
local string l_string;
local integer i;

OUT_Special = false;

clear l_string;
for i = 1 to length(IN_String) do
	l_char = substring(IN_String, i, 1);
	if isalpha(l_char, IN_SpaceAllowed) or (l_char >= str(0) and l_char <= str(9)) then
		l_string = l_string + l_char;
		OUT_Special = true;
	end if;
end for;

OUT_Stripped = l_string;

The function uses the Dexterity isalpha() function as this will handle the extra extended alphabetic characters beyond the normal A to Z and a to z ranges such as é è ë ö ÿ etc.

I have also provided the option to decide whether spaces are to be included as alphabetic.

Hope you find this helpful.


This article was originally posted on

Please post feedback or comments

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s