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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for special characters

Status
Not open for further replies.

hungnguyen

Programmer
Sep 22, 2000
43
US
Hi all,

I have a problem which is I would like to check a text box whether user type some special characters as %, ", ', ^, ~, |. For example, I have a text box name LastName. If user enter as L'Fenta, there would be a message to notify user know that he/she can't enter the character '. I believe that in VBscript we have a function instr; however, how it can be done in Javascript.
Thanks
Hung Nguyen
 
Try indexOf

i.e.

<script>
function SCIB(){
var s1 = &quot;'&quot;
var s2 = document.form.field.value
var s = s2.indexOf(s1);
if (s!=-1)
{alert('No Go Honcho!');}
}
</script>
<body>
<form name=form>
<input type=text value='' name=field>
</form>
<a href=javascript:SCIB(&quot;'&quot;)>Try Me</a>
</body>


Hope that helps. DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
DeltaFlyer,

It does not working. However, I would like to ask you a question what is indexOf function. Where doyou get that function??
Thanks for your help
Hung Ngguyen
 
If you send me an email i will send you the javascript language reference. Can't remember the address at MSDN, sorry.

deltaflyer@bolt.com
DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top