We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

strip bad characters from a textarea

hamishd
hamishd asked
on
Medium Priority
555 Views
Last Modified: 2010-05-18
i am looking for a script that will strip all problematic characters from a textarea (except letters, numbers, commas & fullstops)

any assistance in this area will be appreciated.

thanks
Comment
Watch Question

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Saqib KhanSenior Developer
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
Short description: the badChar are all characters which are NOT listed in the square brackets.
The not char is the first ^ in the set of chars in the brackets.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT

Commented:
oops, shame to me, copy paste error :)
===========
<textarea onkeyup="rep(this)">
</textarea>
<script>
function rep(val)
{
      var badCharacters =["]",";","+"]
      for(var i=0;i<badCharacters.length-1;i++)
      val.value=val.value.replace(eval("/"+badCharacters[i]+"/gi"),"");
}
</script>
CERTIFIED EXPERT

Commented:
devic, the only bad thing about your's is there are a LOT more "bad" characters than good ones, ie different ranges in unicode.

using a regex like the ones contributed by gwynforweb or zvonko, imo, is the way to go.
CERTIFIED EXPERT

Commented:
ren_b  your are right,
but if i want ":" but not ";" etc. and i can simple decide bad chars.
then i think my example is better
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.