Help - Search - Members - Calendar
Full Version: [resolved] Regular expressions
Codegrrl.com Forums > Script Help > Tutorial Help
Vlad
There is some code which prohibits submitting incorrect emails
CODE
if (!eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $_POST['email'])) {
         die("Такого e-mail не может быть!");
    }


Sometimes if it is necessary to prohibit submitting e-mails from one particular server, for example @something.com

I'm not sure with my code, please help me to fix it.

CODE
if (eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([something.com]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $_POST['email'])) {
         die("@something.com is not valid server!");
    }
Majken
I guess this could work just fine:

CODE
if (preg_match("/@something\.com/i",$_POST['email'])) {
     die ('@something.com is not valid server!');
}




Or, if you'd like to keep a list of several prohibited domain names, you could match them in an array - like this:

CODE
if (preg_match("/@(something\.com|whatever\.com|qwerty\.net)/i",$_POST['email'],$match)) {

     die ($match[0] . ' is not a valid server!');

}


Vlad
Thanx, resolved =)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.