|
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
[Back to original message]
|