Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Checking for Special Characters

Not applicable
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!
3 Replies
pguerett
Level 10
Level 10
What is it that is not working ...can hit Ctrl-J and tell us what the console says?
Not applicable
It Says:



checkSpecialCharacters.checkForSpecialChracters(this) is not a function

1:XFA:form1[0]:Content[0]:NarrativeText[0]:exit
Not applicable
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";

}



}