Click to See Complete Forum and Search --> : Stripping Characters out of Strings ?


itsmarkdavies
08-22-2006, 09:29 AM
Hi, i am new to JavaScript so please accept my apologies if this is a simple question.

I need to write a Function that will take a String (entered through a TextBox on an .asp Page by a User), and strip a range of characters (e.g. "," "/" "'" "|") out of it, and replace them with nothing.

For example(s) :-

02/09/1967 should become 02091967
a,b should become ab

Any help appreciated.

Thanks,

Mark.

mark.davies@npower.com

Charles
08-22-2006, 09:46 AM
'02/09/1967'.replace (/\W/g, '')

David Harrison
08-22-2006, 09:46 AM
If you're asking for a date, it may be better to just strip all non-numerical characters out of it, you can do that like so:someVariable = someVariable.replace(/\D/g,"");But remember, not everyone has JavaScript enabled, so you should really do this operation on the server-side with ASP, otherwise users who do not have JavaScript enabled or supported on their browser could cause errors.

itsmarkdavies
08-23-2006, 02:15 AM
Thanks very much Charles / David - i'll give it a go.