View Single Post
  #1 (permalink)  
Old May 17th, 2005, 03:50 PM
ttbhandari ttbhandari is offline
Authorized User
 
Join Date: Sep 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regular Expressions and Replace Function

My valid characters for username are letters and numbers only.
so if the username is abc*67% i want to replace the invalid chars with nothiing. so the correct result should be abc67. i get abc67%.

 I am able to replace only one invalid character. the others stay as it is . any input?

this is my code:-


    username = rtrim(rssqlusername("ag_username"))

    'Test the ag_username for valid chars
    ' Valid Characters Include Letters and Numbers only

    set Regexforinvaliddata = New RegExp
    Regexforinvaliddata.Pattern ="[^A-Za-z0-9 ]"
    set colMatches = Regexforinvaliddata.execute(username)


'Step through our matches
    for each Regexforinvaliddata in colmatches

            searchchar = Regexforinvaliddata.value

            username = replace(username, searchchar, "")
    Next

Reply With Quote