| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
knocking heads
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! |
|
|
|
|
|
#3 (permalink) |
|
Senior Member
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. |
|
|
|
#6 (permalink) |
|
knocking heads
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 |
|
|
|
#8 (permalink) |
|
hmmm...
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. |
|
![]() |