Re: is this correct? regular expressions
| From: | Ernest E Vogelsinger | Date: | Tue, 25 Mar 2003 22:24:49 +0000 |
| Subject: | Re: is this correct? regular expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141024@lists.php.net to get a copy of this message | ||
At 23:22 25.03.2003, Jay Paulson said:
--------------------[snip]--------------------
>just trying to say if $phone isn't all numbers set it to all zeros.. so is
>that right? cause i can't seem to get it to work.
>
> if (!ereg("^[0-9]$",$phone)) {
> $phone = "0000000000";
> }
>
>thanks!
--------------------[snip]--------------------
This is "if $phone is anything else than a single digit". You need to add
either a plus or an asterisk after the closing bracket to denote multiple
instances of the character set:
if (!ereg("^[0-9]*$",$phone)) {
You could also check if anything _not_ being a number exists within $phone:
if (ereg("[^0-9]",$phone)) {
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/