Paul,
It is working now. I don't know what I might have changed.
Here's my final function (It works!):
function checkForSpecialChracters(oFiled)
{
var userInput = oFiled.rawValue; // take the String entered by the user
var iChars = "@#$%^&*+=-[]\\\';,./{}|\":<>?~_";
var hasSpecialCharacter = false;
for (var i = 0; i < userInput.length; i++)
{
//app.alert("Value is: " + userInput.charAt(i));
if (iChars.indexOf(userInput.charAt(i)) != -1)
{
hasSpecialCharacter = true;
break;
} // end if
} // end For loop
if (hasSpecialCharacter)
{
// Change the color of the field
oFiled.fillColor = "255,100,50";
xfa.host.messageBox("Please check for special characters. \n\nThe following characters are not allowed:\n\n @#$%^&*+=-[]\\\';,./{}|\":<>?~_ ", "Error Message", 3);
}
else if (!hasSpecialCharacter)
{
oFiled.fillColor = "255,255,255";
}
}