...

View Full Version : regexp help... only numbers and chars



homerUK
03-17-2004, 08:18 PM
Hey,

I've tried the search on this site and come up with the following

alert(text.replace(/[^A-z-' ']/g,""));

but it doesnt seem to work....

what I need is to allow only characters and numbers in the string, oh and curly braces....

eg: text = "{hello},"

I need to strip everything but chars, numbers and { }

this reg exp thing is a nightmare!!!!
please some one help!!

Choopernickel
03-17-2004, 08:22 PM
alert(text.replace(/[^\a\d{}]/g))

might work for you. Liorean's got a couple of great regex tutorials linked from his sig -- check those out.

homerUK
03-17-2004, 08:27 PM
cheers... that seems to strip out all chars apart from "a" ??

text = "{firstname},";

alert(text.replace(/[^\a\d{}]/g,''));

shows

{a}

:confused:

liorean
03-17-2004, 08:46 PM
Choopernikel: Actually, just one article, but from both places it's been publiciced.


homerUK: text.replace(/[^a-z0-9{}]/gi,'');

homerUK
03-17-2004, 09:45 PM
thanks - works perfectly :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum