Jump to content

Replace any character with exceptions


mike_g

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...