Page 1 of 1

Validation Codes

Posted: Mon May 29, 2006 3:08 pm
by tecktalkcm0391
Can someone help me with this or explain it more.

I want to validate the variable $username. I want it to have only these values allowed:


A-Z
a-z
0-9
_

How could I do this? I got an idea, but I am so confused with the eregi(); command.

Also how can I make the variable $email have to be in the normal e-mail format with only these characters allowed:

A-Z
a-z
0-9
.
-
_



Thanks.

Posted: Mon May 29, 2006 3:24 pm
by Chris Corbyn
You chose the perfect characters for the \w metacharacter.

Code: Select all

$var = 'sfdg6765_vgdz';

if (preg_match('/^\w+$/', $var)) echo 'Valid!';
As for the email question, there's a tonne of available pattern out there to use - have a search :)

Re: Validation Codes

Posted: Mon May 29, 2006 3:28 pm
by Roja
tecktalkcm0391 wrote:Also how can I make the variable $email have to be in the normal e-mail format with only these characters allowed
The RFC compliant email format uses more than just those characters. There are multiple RFC compliant validation formats that have been posted on these forums, including one I use.