mike_g Posted May 11, 2007 Share Posted May 11, 2007 Hi, I'm working on some validation functions at the moment using string replace(). What I have been doing so far seems tediously slow. For example, to strip all alpha characters from a string I have been doing this: str = str.replace(/a/gi, ""); From A through to Z.Now I want to strip all characters except for numbers. I imagine there must be a faster way then simply running a string replace for every other character. Is this possible? Suggestions appreciated Link to comment Share on other sites More sharing options...
jesh Posted May 11, 2007 Share Posted May 11, 2007 str = str.replace(/[^0-9]/gi, ""); Check out this site for some good regular expressions tutorials/references: http://www.regular-expressions.info/ Link to comment Share on other sites More sharing options...
mike_g Posted May 11, 2007 Author Share Posted May 11, 2007 Cool, thanks for that. Link to comment Share on other sites More sharing options...
jesh Posted May 11, 2007 Share Posted May 11, 2007 Any time. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.