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
BedrockMission!

Learn More

View all

Sign in to view all badges

Checking for Special Characters

Avatar

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

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

03-11-2008

What is it that is not working ...can hit Ctrl-J and tell us what the console says?

Avatar

03-11-2008

It Says:



checkSpecialCharacters.checkForSpecialChracters(this) is not a function

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

Avatar

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

}



}