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

Posted by Rik on 05/06/06 16:16

Rik wrote:
> 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]?))?$/'

Hmmmz, some mistake, I thought the format was 000-000@000-000

For int1-int2@float1
0 < int1 <= 500
0 < int2 <= 500
0 < float <= 10000
'/^(500|[1-4][0-9]{2}|[1-9][0-9]?)(-(500|[1-4][0-9]{2}|[1-9][0-9]?))?@(10000
(\.0*)?|[1-9][0-9]{4}(\.[0-9]*)?|0\.0*[1-9]+0*)$/'

But still, for portability (I've disallowed 0 in int's and 0.0000etc.. in
float, no leading zeroes except in case of float 0*point*something other
then just zeroes):
preg_match('/^([1-9][0-9]*)(?:-([1-9][0-9]*))?@(0\.0*[1-9]+0*|[1-9][0-9]*(?:
\.[0-9]*)?)/', $string, $matches)
$matches[1] = int1
$matches[2] = int2
$matches[3] = float1
Do further validating with $matches array.

Offcourse, allowing (leading) zeroes makes it much easier:
preg_match('/^([0-9]+)(?:-([0-9]+))?@([0-9]+(\.[0-9]+)?/', $string,
$matches)

Grtz,
--
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

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