Reply to Re: Simple ereg help

Your name:

Reply:


Posted by John Dunlop on 10/19/06 14:55

ollie.mitch@gmail.com:

> I need two ereg expressions in my PHP code. One of them needs to check
> that a string only contains letters,

'letters' means A-Z?

(untested)

preg_match('/\A[a-z]+\z/i',$subject)

Meaning: match, starting at the beginning and finishing at the end,
one or more letters, case insensitive.

> and the other needs to check that the string only contains
> letters and commas (only one comma at each time).

(untested)

preg_match('/\A(,(?!,)|[a-z]*)+\z/i',$subject)

Meaning: match, one or more times, a comma that is not followed by
another comma or match zero or more letters.

> I thought that the code for only containing letters would be:
>
> eregi("^([a-z])", $keywords);
>
> But this only appears to be checking the first character.

Yeah, you haven't quantified the character class, e.g., /^[a-z]+/, or
anchored the pattern to the end of the subject, e.g., /^[a-z]+$/.

--
Jock

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация