|
Posted by mvandenb on 02/16/07 21:08
On Feb 16, 6:55 am, raj <r...@nospam.com> wrote:
> Hi,
>
> I have to repost this to restate the question. No disrespect to the original
> reply.
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I need to do this using ereg
>
> I've got as far as this but it doesn't quite work:
>
> $pattern="^([a-z0-9.-_]{0,30})$";
> if(ereg($pattern,$_SESSION['id']))
> ...
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)
So you have written
$pattern="^([a-z0-9.-_]{0,30})$"
match a to z, 0 to 9, "." to '_' starting at the beginning of the line
and ending at the end of the line with a maximum of 30 character and a
minimum of 0 character.
they are right about preg_match. which all it means is you need to
wright you regex slightly differently and you can do fancy things if
you wanted to.
http://www.perl.com/doc/manual/html/pod/perlre.html
so
"/^[\w\.\-]{0,30}$/
or
"/^[a-zA-Z0-9\_\.\-]{0,30}$/
which is the same thing just longer to write out
and these are generally case sensitive remember so 'a' != 'A' (hence a-
zA-Z and not just a-z)
try that or at lest it should give you a good direction
Navigation:
[Reply to this message]
|