Re: ICQ # validation
| From: | Hans Prins | Date: | Tue, 04 Mar 2003 11:27:13 +0000 |
| Subject: | Re: ICQ # validation | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138081@lists.php.net to get a copy of this message | ||
Also, don't forget to escape the $ character in your expression, since it is
reserved for variable declaration.
"Ales KrajníK" <ales@jikos.cz> schreef in bericht
news:20030304081835.2874.qmail@pb1.pair.com...
> Well ...
>
> - the {7,9} means that the previous char/group should repeat 7 to 9 times
> ...
> - ^ means the beginning of the string
> - $ means the end of the string
>
> So everything, that validates, is 7 to 9 numbers.
>
> "123456789 This is a test" won't validate - it contains chars instead of $
> (end of string) after [0-9]{7,9} = 7 to 9 numbers.
>
> And yes, you can use something like [[:digit:]] but I must admit I don't
use
> that much.
>
> Ales
>
> <SLanger@spirit21.de> wrote in message
>
news:OF09467EC1.D09E7DC2-ONC1256CDF.002C7A3A-41256CDF.002CDF08@spirit21.de..
> .
> > > if(ereg("^[0-9]{7,9}$", $_REQUEST["icqnumber"])) {
> > > >> print("a-okay!");
> > > >> } else {
> > > >> print("error msg");
> > > >> }
> >
> > Although I'm not too familiar with regexp I'd say the code validates
> > because the icq number you are providing actually confimrs to the
pattern.
> > The first seven to nine digits contain only numbers so the pattern is
> > true. Th ce pattern does not check the length of your provided string.
> > If I'm correct than "123456789 This is a test" will also proof to be
> > correct. So you have to do two things first check the whole argument for
> > digits like
> > ereg('^[0-9]{'.strlen($_REQUEST['icqnumber']).'}',
> > $_REQUEST['icqnumber']) and check length separatly. (U can also use
> > [[:digit:]]) Or use the code as mentioned before.
> > In your place I would not assume anything about the length of the icq
> > number.
> >
> > Hope that helps
> > Stefan
> >
> > P.S.: Please correct me if I'm wrong with the above!!!!
>
>