Re: Syntax?
| From: | Ignacio Vazquez-Abrams | Date: | Wed, 03 Jan 2001 20:07:41 +0000 |
| Subject: | Re: Syntax? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32541@lists.php.net to get a copy of this message | ||
On Wed, 3 Jan 2001, James, Yz wrote:
> Hey! This is the first time I have written to a newsgroup...... And being
> a newbie, I need help ;)
>
> OK, I have several scripts I have successfully done. At the moment, I'm
> working on setting up a database for friends. The only thing I am really
> struggling on is prohibiting them from using non alpha-numeric (I don't even
> know whether that's the right term(!)) in their alias when signing up.
>
> Basically, their name should comprise of letters, numbers (if necessary),
> the underscore character and nothing else. I put this code together, which
> basically varifies whether the name is comprised of numbers only:
>
> if (ereg ("([0-9])", $alias)) {
> echo "Okie Dokie $alias, you can register a name comprised of numbers.";
> } else {
> echo "Invalid name: $alias";
> }
>
> I don't want them to be able to use spaces either.
>
> Please try to bear in mind that I'm not only relatively new to PHP, but a
> complete novice to Perl.
>
> Can anyone help?
>
> Thanks ;)
>
> James.
>
The RE you want is "^[[:alnum:]_]+$". If it has to start with a letter, use
"^[[:alpha:]][[:alnum:]_]*$" instead.
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>