Reply LinkBack Thread Tools Search this Thread
Old 26-10-2006, 06:09   #1 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: London, UK
Posts: 1,914
Javascript auto remove invalid characters

Regex's have never been my strong point...

I need a javascript function that automatically removes any chracter entered into a form field EXCEPT for a-z A-Z 0-9 ' _ , ( ) @ $ £ & -

any help would be appreciated!
  Reply With Quote
Old 26-10-2006, 06:22   #2 (permalink)
smallbeer
I Ain't Losing Any Sleep™
 
Join Date: Apr 2003
Posts: 5,200
how do you mean "automatically"? you mean when the the form is submitted?
__________________
That's fuckin' ingenious, if I understand it correctly. It's a Swiss fuckin' watch.
  Reply With Quote
Old 26-10-2006, 07:28   #3 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,175
If you are doing this to validate user input to prevent SQL injection - I would also make sure your php (or whatever language you use) also does the same, as JS can be disabled and bots usually don't have it.

I'm guessing it is for a contact form, if so you are probably best to validate each input using a different criteria, as some of those characters dont belong in email addresses, etc.
  Reply With Quote
Old 26-10-2006, 10:42   #4 (permalink)
Suigeneriz
Norwegian Viking™
 
Join Date: Oct 2006
Location: Norway
Posts: 55
Write your own shitt:P
  Reply With Quote
Old 26-10-2006, 10:55   #5 (permalink)
d*d
Moderator
 
d*d's Avatar
 
Join Date: Oct 2004
Location: Bristol
Posts: 3,299
Quote:
Originally Posted by Suigeneriz
Write your own shitt:P

that's the spirit, enjoy your stay
  Reply With Quote
Old 26-10-2006, 10:58   #6 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: London, UK
Posts: 1,914
by automatically, i mean as you type, it removes the "bad" character - don't worry about that part, i can handle it..! (it was just to give you some idea of what i was trying to achieve)

more importantly, i just need help with the regex

freelancr - dont worry, the javascript is just being used to make the interface more user friendly, there is a lot of checking on the server side
  Reply With Quote
Old 26-10-2006, 11:51   #7 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,175
removing stuff as you type eh, that sounds clever, if you get it to work post up a link of an example!
  Reply With Quote
Old 27-10-2006, 08:56   #8 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
Can you capture the input before it gets through, in which case you'd just need to match on those:
[A-Z0-9'_,()@$£&]

Then just reject anything that doesn't match. Might need some escapes in there though.
__________________
George Smith - a vain attempt to get higher on google for my name

  Reply With Quote
Old 28-10-2006, 05:36   #9 (permalink)
Suigeneriz
Norwegian Viking™
 
Join Date: Oct 2006
Location: Norway
Posts: 55
Yeah freelancr are not the only one who would like a link
  Reply With Quote
Old 28-10-2006, 05:53   #10 (permalink)
Suigeneriz
Norwegian Viking™
 
Join Date: Oct 2006
Location: Norway
Posts: 55
Going to try to make that javascript function myself.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8