I want to use a basic regular expression to check whether a string contains only numbers and alphabet characters so I tried
preg_match('[a-zA-Z0-9]*', $address)
Which unfortunately returns an error:
Warning: preg_match() [function.preg-match]: Unknown modifier ‘*’ in /bla/bla.php on line XX
It’s a simple regex. Where am I getting it wrong?
The pattern should begin and end with a pattern delimiter. Different preg options, like case-insensitive search can be added after the delimiter. Usually slash (/) is used for delimiter, but can be any symbol (the delimiter should be escaped in the pattern):
This will check if the string has numbers or characters in it.
If you want to make sure that it has only numbers and characters, then use this: