Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex: test for alphanumeric only
#1
Basically I'm trying to eliminate potential problems when exporting user-entered text strings for use downstream of the macro (filenames, html, php, mysql etc.).

What is the best way to do both of these options:

A. Validate that a string contains only contains letters and numbers? (i.e. so I can throw up a message saying "Use only alphanumeric characters" when any special character/non-alphanumeric character exists in a text string)


B. Instead of forcing the user to re-enter/fix string, simply go ahead and replace invalid characters with an underscore like here:

Code:
Copy      Help
u.lcase
u.replacerx(" |-|#" "_")

but without having to list every undesirable character in the replacerx pattern. Essentially the equivalent expression that results in "for each character exists that is not alphanumeric, replace with '_' " (I should mention that I will not have to restore any of the characters removed at a later point).


Thanks in advance for any help!

Steve


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)