I am trying to create a RegEX to validate my home address string. The requirement is : must be more than 1 char and consist of any of the below char (not all required):
1 #
2 numbers(0 to 9)
3 alphabets(A/a to Z/z)
4 comma: ,
5 hyphen: -
6 underscore: _
7 dot: .
8 brackets: ( )
9 space
10 backslash: /
I thought this would be simple but I cannot figure out. Could you please help? There is no need to make this complicated so something like "111" would work. Just a string that allows all chars above.
Thanks
Home Address string (with special characters)
Moderator: General Moderators
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Home Address string (with special characters)
Something like this perhaps?
Code: Select all
$address = "Street Name 25 B";
if (preg_match('~^[-.,_()#/a-z\s\d]{2,}$~i', $address)) {
echo "'$address' matched!";
}