Highlighted

Checking for Special Characters

Avatar

Guest

03-11-2008

I need to check if a textbox in my form containes special characters (entered by user). If there are any, I need to display an error message.



I have written a function but it's not working.

here's my function:



function checkForSpecialChracters(oFiled)

{

var userInput = oFiled.rawValue; // take the String entered by the user

var iChars = "@#$%^&*+=-[]\\\';,./{}|\":<>?~_";



for (var i = 0; i < userInput.length; i++)

{

if (iChars.indexOf(userInput.charAt(i)) != -1) {



xfa.host.messageBox("Please check for special characters. The following characters are not allowed: @#$%^&*+=-[]\\\';,./{}|\":<>?~_ ", "Error Message", 3);

// Change the color of the field

oFiled.fillColor = "255,100,50";



}

}



Any help would be greatly appreciated.

Thank you!

Replies

Highlighted

Avatar

Guest

03-11-2008

It Says:



checkSpecialCharacters.checkForSpecialChracters(this) is not a function

1:XFA:form1[0]:Content[0]:NarrativeText[0]:exit
Highlighted

Avatar

Guest

03-11-2008

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";

}



}