Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

character string test

Status
Not open for further replies.
Apr 27, 1999
705
US


Hello,

I have an input form field myname. I need to test of any of these characters are in this field using javascript.

% \ / ' " @ = ) ( < > &

If so, I would like to replace that character in the string at that location.
Any ideas?

Thanks in advance
fengshui1998

 
How about a regular expression?

Code:
var invalidchars="[%\\/'\"@=)(<>&]";
[green]\\Quotes and backslashes need to be escaped with another backslash in the regular expression[/green]
var txt=new RegExp(invalidchars,"g");
[green]\\Define the regular expression variable[/green]
var mystring='This % string @ " contains = seve/ral ( invalid <> chars';

alert(mystring.replace(txt,"*"));




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top