You are here: Re: [PHP] regular expression for integer range « PHP « IT news, forums, messages
Re: [PHP] regular expression for integer range

Posted by Robin Vickery on 09/07/05 12:14

On 9/6/05, babu <garavindbabu@yahoo.co.uk> 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

 

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

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