Hi,
I need one function to validate streetnames and one to validate names.
I tried to write my own regular expression and to use preg_match,
but for some weird reason I can't get it to work.
Valid names should be:
Peter
Christian-Peter
Li
Li Yan Young
Li - Yan - Young
Li- Yan -Young - Mei
Valid streetnames should be:
Jackrippperstr. 10a
Jackrippperstr 9391 B
Jack-The - Ripper Str. 3
Jack -The- Ripper B
Jack -The- Ripper
Here are my regular expressions:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++
/*/////////////
///1. Names ///
/////////////*/
//At least 2 chars:
$twochars ="(A-Za-zßäüöÄÜÖ){2,}"; //Including german special chars
// Separator with space and or -
$separator= "([:space:]?-[:space:]?|[:space:])";
/*
(Name consists of at least 2 chars, optionally followed by one space
char and or - , followed by again at least 2 chars )+
*/
$name= "($twochars($se parator$twochar s)*)+";
if ( preg_match("/$name/",$value) )
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++
/*///////////////////////////
///2. Streetname + number ///
///////////////////////////*/
//At least 2 chars:
$twochars ="(A-Za-zßäüöÄÜÖ){2,}"; //Including german special chars
// Separator with space and or -
$separator= "([:space:]?-[:space:]?|[:space:])";
// optionally Str. or Str or str or Str.
$str = "([Ss]tr|[Ss]tr.)?";
/*
The numbers (1-9 followed by 0-9 ) - zero or four times, followed by
space or not, optionally followed by a character.
*/
$nr = "((1-9)+(0-9)*){0,4}[:space:]?(A-Za-z)?";
$street= "($twochars($se parator$twochar s)*)+$str$nr";
if ( preg_match("/$street/",$value) ) ...
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++
Have you any idea why this doesn't work?
Thanks,
Stefan
I need one function to validate streetnames and one to validate names.
I tried to write my own regular expression and to use preg_match,
but for some weird reason I can't get it to work.
Valid names should be:
Peter
Christian-Peter
Li
Li Yan Young
Li - Yan - Young
Li- Yan -Young - Mei
Valid streetnames should be:
Jackrippperstr. 10a
Jackrippperstr 9391 B
Jack-The - Ripper Str. 3
Jack -The- Ripper B
Jack -The- Ripper
Here are my regular expressions:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++
/*/////////////
///1. Names ///
/////////////*/
//At least 2 chars:
$twochars ="(A-Za-zßäüöÄÜÖ){2,}"; //Including german special chars
// Separator with space and or -
$separator= "([:space:]?-[:space:]?|[:space:])";
/*
(Name consists of at least 2 chars, optionally followed by one space
char and or - , followed by again at least 2 chars )+
*/
$name= "($twochars($se parator$twochar s)*)+";
if ( preg_match("/$name/",$value) )
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++
/*///////////////////////////
///2. Streetname + number ///
///////////////////////////*/
//At least 2 chars:
$twochars ="(A-Za-zßäüöÄÜÖ){2,}"; //Including german special chars
// Separator with space and or -
$separator= "([:space:]?-[:space:]?|[:space:])";
// optionally Str. or Str or str or Str.
$str = "([Ss]tr|[Ss]tr.)?";
/*
The numbers (1-9 followed by 0-9 ) - zero or four times, followed by
space or not, optionally followed by a character.
*/
$nr = "((1-9)+(0-9)*){0,4}[:space:]?(A-Za-z)?";
$street= "($twochars($se parator$twochar s)*)+$str$nr";
if ( preg_match("/$street/",$value) ) ...
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++
Have you any idea why this doesn't work?
Thanks,
Stefan
Comment