[PHP] Re: Q on RegExp & extended Char

2003-12-16 Thread Sven
Jswalter schrieb:

...
 - allow apostrophes, but only if preceded *and* followed by a Alpha/Extend
 - allow hyphen/dash, but only if preceded *and* followed by a Alpha/Extend
...

hi walter,
how about something like this:


$_alpha  = 'a-zA-Z'; // standard latin letters
$_xascii = '\x80-\xFF';  // extended ascii-codes
$_achar  = $_alpha.$_xascii; // allowed characters
$regex = '/^['.$_achar.']+(\'|-)['.$_achar.']+$/';

?>

hth SVEN

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Q on RegExp & extended Char

2003-12-15 Thread jsWalter
I should have posted some "rules" with this...

assuming:
 - a SPACE is used to delimit first from last name [Walter Torres]
 - a HYPHEN is used to separate a dual name (British style) [Conrad-Smyth]
 - an APOSTROPHE is used in many Irish and Scotish names [O'Reilly]
 - a PERIOD is used in titles, suffixes [Dr. Sr. Jr.]
 - a PERIOD is used for Initials [Walter G. Torres]

then...
 - allow apostrophes, but only if preceded *and* followed by a Alpha/Extend
 - allow hyphen/dash, but only if preceded *and* followed by a Alpha/Extend
 - allow PERIOD, but only if preceded by a Alpha/Extend *and* followed by a
   SPACE or EOS
 - allow SPACE, but only if preceded *and* followed by a Alpha/Extend

also...
 - allow x80 thru xFF

I've come up with this...

/^([a-z\x80-\xFF]+(. )?[ ]?)+$/i
   |_||___||__| ^
   ^^   ^   |
   ||   |   | whole block ONE or more times
   ||   |
   ||   | SPACE - ZERO or ONE times
  alpha & extended  |
  ONE or more   | PERIOD - ZERO or ONE times


but I can't seem to figure out how to get the HYPEN & apostrophe rules in
here.

But this does allow multiple spaces - which It really shouldn't but...

It also lets me add SPACEs at the end, oh well...

Any ideas?

Thanks

Walter

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Q on RegExp & extended Char

2003-12-15 Thread Sven
Jswalter schrieb:
I've hit my limit on regular expressions.

I need to check a string to see if it contains legal characters...

A thru Z [a-z], SPACE, PERIOD, DASH/HYPHEN, APOSTROPHE [\' -,\.]

OK, this is not a problem.

My problem comes in with extended characters, as these examples...
  González
  Vänligen
  före
  innehålla
I'm trying to build a RegExp that will see if the string is a proper name
format or not.
Names only have A thru Z, extended characters for other languages (than
English), SPACE, PERIOD, DASH/HYPHEN, APOSTROPHE
  Dr. Roger O'Malley
  Mrs. Sara Harris-Henderson
I have a RegExp to do English letters, but not the extended set...
  Manuel González
  Försök Bokstäver
  Contém Espaço-Válido
(Ok, these are not really names, but you get the idea)

Any ideas on this?

All I want to know is if a given string contains only these types of
characters. anything else would give me a FALSE.
Thanks
Walter
hi walter,
because most of these chars are extended ascii (decimal: 128-255), this 
regex should work: '/\x80-\xFF/' (hex-values). also take care of the 
minus in your regex if it doesn't stand on start or end of your 
char-group it means 'from-to'!
hth SVEN

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Q on RegExp & extended Char

2003-12-15 Thread Jas
Well have you thought about maybe an array of illegal or extended 
characters and simply replacing them?
eg.
$b = $_POST['whatever_variables_you_have'];
$match = array("ö","ç","ä");
$replace = array("o","c","a");
$z = str_replace($match,$replace,$b);

Might not be exactly what you want but hope it helps.
Jas
Jswalter wrote:
I've hit my limit on regular expressions.

I need to check a string to see if it contains legal characters...

A thru Z [a-z], SPACE, PERIOD, DASH/HYPHEN, APOSTROPHE [\' -,\.]

OK, this is not a problem.

My problem comes in with extended characters, as these examples...
  González
  Vänligen
  före
  innehålla
I'm trying to build a RegExp that will see if the string is a proper name
format or not.
Names only have A thru Z, extended characters for other languages (than
English), SPACE, PERIOD, DASH/HYPHEN, APOSTROPHE
  Dr. Roger O'Malley
  Mrs. Sara Harris-Henderson
I have a RegExp to do English letters, but not the extended set...
  Manuel González
  Försök Bokstäver
  Contém Espaço-Válido
(Ok, these are not really names, but you get the idea)

Any ideas on this?

All I want to know is if a given string contains only these types of
characters. anything else would give me a FALSE.
Thanks
Walter
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php