You are here: Re: Regular Expressions « All PHP « IT news, forums, messages
Re: Regular Expressions

Posted by Rik on 05/06/06 14:47

Martie wrote:
> May be worth trying something using the "preg_match()" function. With
> the first example you had I was able to get that to work with the
> following. Though I did just catch the potential for "501", so it
> needs a littel more tweaking.
> '/^[1-5]*[0-9]*[1-9]+\-[1-5]*[0-9]*[1-9]+\@[1-9]+[0-9.]*$/'

If leading zeroes have to be impossible, and 500 is indeed the highest
number allowed:

'/^(500|[1-4][0-9]{2}|[1-9][0-9]?)(-(500|[1-4][0-9]{2}|[1-9][0-9]?))?@(500|[
1-4][0-9]{2}|[1-9][0-9]?)(-(500|[1-4][0-9]{2}|[1-9][0-9]?))?$/'

allthough a simple:
$regex = '/([1-9][0-9]*)(-([1-9][0-9]*))?@([1-9][0-9]*)(-([1-9][0-9]*))?$/'

preg_match_all($regex, $text, $matches):

if($match[1]>500||$match[3]>500||$match[4]>500||$match[6]>500){
//number is higher then allowed
}

might be more readable.

--
Rik Wasmus

 

Navigation:

[Reply to this 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

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