I'm trying to validate a variable passed through a form by the user. Using reg exp I want to check if the variable contains any other characters than a-z 0-9 _ . - ( ) [ ] . However, it doesn't seem to work with the ] and [. If I remove them from the reg exp it works. Here's what I have so far:
eregi("[[]a-z0-9_.()-]", $var)
What is wrong here?
Could try: preg_match('/[a-z0-9_.-()[]]/', $var)
Or if the brackets are still giving problems, then: preg_match('/[a-z0-9_.-()\x5B\x5D]/', $var)
incidentally, you might want to use: /[a-z0-9_.-()\x5B\x5D]/i for case-insensitive matching
Allright, that works perfectly! Thanks.