Re: Re: Ereg/replace/i/ or something ??
| From: | Lars Torben Wilson | Date: | Wed, 30 Jan 2002 20:04:04 +0000 |
| Subject: | Re: Re: Ereg/replace/i/ or something ?? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-82809@lists.php.net to get a copy of this message | ||
On Wed, 2002-01-30 at 08:16, liljim wrote:
> Hi Bart,
>
> > I want to check the data from a form-field if it excists only of digits
> > (0-9) and nothing else.
> >
> > How do I use the ereg()-function for this?
>
> Well, I prefer the preg_functions
>
> if (!preg_match("/^[0-9]{10}$/", $string)) {
> // contains stuff other than numbers, or is less than 10 digits in length.
> }
>
> You could also just use is_int()
> http://www.php.net/manual/en/function.is-int.php
> and strlen()
> http://www.php.net/manual/en/function.strlen.php
Just a small correction--you should use is_numeric(), not is_int();
form fields are always presented as strings.
Torben
--
Torben Wilson <torben@php.net>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
+1.604.709.0506