|
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]
|