Page 1 of 1

Home Address string (with special characters)

Posted: Sat Jun 21, 2008 12:37 am
by cohq82
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

Re: Home Address string (with special characters)

Posted: Sat Jun 21, 2008 2:36 am
by prometheuzz
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!";
}