I've got a small 'business' app in dev that my client will use to let people enter their data in a mySQL database (through a PHP script).
Now my challenge is removing all illegal characters from their first name and last name text fields (this mostly to prevent users from entering database commands that could screw things up for me).
I've tried a lot of option already using lua patterns and string.match or string.gsub, but nothing that really covers all my bases. I also have to admit that the pattern notation boggles my mind.
My main pattern problem is that name entries need to allow for spaces and hyphen/dash characters. I can run some patterns that remove punctuation and control characters, but that also removes the hyphen. Conversely, only allowing alphabetical characters does not allow for spaces or the hyphen. In a sense, a pattern that would say "replace all non-alphabetical characters with "" except for a space or hyphen" would work perfectly. But as I said, I have a hard time fully understanding the pattern lingo...
So my question:
- Does anyone have a good method for taking all illegal characters out of a name string, but still allowing spaces and a hyphen/dash character?
If all else fails, I will probably do this character per character, check the ASCII code and append to a new empty string if the character is allowed, but I feel like there is a pattern solution that should work...