String sent to function, needs to return only alphanumeric values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MGM
    New Member
    • Aug 2007
    • 19

    String sent to function, needs to return only alphanumeric values

    Hey everyone, I had a quick problem:

    I want to be able to send a string of data to a function and have it return that same string but only in alphanumerics. That is to say, if I sent it:

    "Hello world 1!"

    It should return:

    "Helloworld 1"

    Is this possible? I know I can do a verification using RegEx, but I want to actually alter the string to return only alphanumeric. Any help would be much appreciated!

    MGM out
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    You can use the same RegExp pattern to replace as well as to test-

    string=string.r eplace(/\W+/g,'');

    Comment

    Working...