Re: regular expression for integer range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/6/05, babu <garavindbabu@xxxxxxxxxxx> wrote:
> Hi all,
> 
> 
> I want to write regular expression for checking the string format entered by user.
> 
> the allowed formats are
> 
> examples:
> 10
> 10,
> 10,12-10
> 12-10
> 
> that is the valid strings are:
> 1. only integer
> 2. an integer, range of integers example 3
> 
> and no other characters must be allowed.

$re = '/^(\d+)(,\d+-\d+)?$/';
preg_match($re, $value);

This only allows
 * an integer or
 * an integer followed by a comma and a range of integers

It doesn't allow anything else - even whitespace after the comma.

 -robin

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux