I have already tried to include - in code but I always have problem
What is the correct way to include this character "-" in
!preg_match("/^[a-zA-Z0-9\. ]*$/", $home)
Thanks
I have already tried to include - in code but I always have problem
What is the correct way to include this character "-" in
!preg_match("/^[a-zA-Z0-9\. ]*$/", $home)
Thanks
Inside character classes, -
signs need to be escaped like this:
!preg_match("/^[a-zA-Z0-9\. \-]*$/", $home);
Also, you can drop A-Z
from the character class and add the i
flag to the regex like this:
!preg_match("/^[a-z0-9\. \-]*$/i", $home);
From the manual:
If a minus character is required in a class, it must be escaped with a backslash or appear in a position where it cannot be interpreted as indicating a range, typically as the first or last character in the class.