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!

Help with special characters please..

Status
Not open for further replies.

macmac1

Programmer
Jan 20, 2002
11
US
I am trying to through a erro if the user puts a special character in a form field. I have some code that works great but it saying a blank space is a invalid charachter. here is the code that is buggin...

function zipcheck() {
var mikExp = /[!\?\$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\'\:\;\""\ ]/;
if(the_form.zip.value.search(mikExp) != -1)
{
alert("Sorry, but the following characters\n\r\n\r@ $ % ^ & * # ( ) [ ] \\ { + } ` ~ = | : ; ! ? ' \n\r\n\rare not allowed!\n");
the_form.zip.focus();
return false;
}
}
 
Hi macmac1,

I don't understand the code but if I take a "logical" look maybe it's because you end with: \ ]

Maybe the functions see this as \space]

Further I see some "proberbly" mistakes?:
- I miss the underscore "_" in the list Sorry, but the ...."
- Is this ...\\@\\\#%... OK , shouldn't it be something like ...\@\\\#\%... (again , I don't understand the code but I can think a bit what is does, but maybe I'm totaly wrong)

I hope this helps you a bit,
Erik
<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top