Re: Preg_match.
| From: | Ignacio Vazquez-Abrams | Date: | Fri, 08 Dec 2000 17:43:15 +0000 |
| Subject: | Re: Preg_match. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29380@lists.php.net to get a copy of this message | ||
On Fri, 8 Dec 2000, Monte Ohrt wrote:
> actually, I wasn't exactly what you wanted.
> Try this:
>
> if (preg_match("/^[^._][a-zA-Z0-9._]*[^._]$/",$string) &&
> strlen($string) < 21)
> echo "good";
> else
> echo "bad";
>
> That should cover it.
>
> Monte Ohrt wrote:
> >
> > /^[^._][a-zA-Z0-9._]{2,20}[^._]$/
> >
> > Jonatan Bagge wrote:
> > >
> > > Hi
> > >
> > > I'm trying to make a regular expression for use with preg_match to meet
> > > the following criterias:
> > >
> > > May contain: a-z A-Z 0-9 _ .
> > > May not start nor end with: . _
> > > Must be: 2-20 characters long
> > >
> > > I know this is a really easy one but let's face it I truly suck at
> > > regular expressions.
> > > Also..Please don't flame me for being OT.
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-general-help@lists.php.net
> > > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> > --
> > Monte Ohrt <monte@ispi.net>
> > http://www.ispi.net/
> >
>
> --
> Monte Ohrt <monte@ispi.net>
> http://www.ispi.net/
>
No, that won't do it either. Try:
/^[0-9a-zA-Z][0-9a-zA-Z._]{,18}[0-9a-zA-Z]$/
FYI, you probably have your reason(s) for using preg, but here's the
equivalent in ereg:
^[[:alnum:]][[:alnum:]._]{,18}[[:alnum:]]$
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>