Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 18:10

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



email syntax überprüfen

Discussion on email syntax überprüfen within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2011
Posts: 85
Received Thanks: 4
email syntax überprüfen

hallo leute,
ich wollte heute ein script schreiben was den syntax der email überprüft
da ich nicht so recht wusste wie ich dies anfangen soll googlte ich dies im internet und traf auf diesese hier:
if(preg_match("/^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$/",$mail))

nur leider versteh ich das noch nicht so recht ...
was genau macht preg match und wie ist das ganze in der klammer zu verstehen aufgebaut....
Dies hilft mir auch nicht so recht....
xTrojaner is offline  
Old 03/12/2012, 08:25   #2


 
Whoknowsit's Avatar
 
elite*gold: 146
Join Date: May 2009
Posts: 3,764
Received Thanks: 6,974
Einen Regex zu erklären ist in manchen Fällen garnicht so einfach

Ich persönlich mach's mittlerweile so:

PHP Code:
function check_email_address($email)
{
   
$isValid true;
   
$atIndex strrpos($email"@");
   if (
is_bool($atIndex) && !$atIndex)
   {
      
$isValid false;
   }
   else
   {
      
$domain substr($email$atIndex+1);
      
$local substr($email0$atIndex);
      
$localLen strlen($local);
      
$domainLen strlen($domain);
      if (
$localLen || $localLen 64)
      {
         
// local part length exceeded
         
$isValid false;
      }
      else if (
$domainLen || $domainLen 255)
      {
         
// domain part length exceeded
         
$isValid false;
      }
      else if (
$local[0] == '.' || $local[$localLen-1] == '.')
      {
         
// local part starts or ends with '.'
         
$isValid false;
      }
      else if (
preg_match('/\\.\\./'$local))
      {
         
// local part has two consecutive dots
         
$isValid false;
      }
      else if (!
preg_match('/^[A-Za-z0-9\\-\\.]+$/'$domain))
      {
         
// character not valid in domain part
         
$isValid false;
      }
      else if (
preg_match('/\\.\\./'$domain))
      {
         
// domain part has two consecutive dots
         
$isValid false;
      }
      else if(!
preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 
str_replace("\\\\","",$local)))
      {
         
// character not valid in local part unless 
         // local part is quoted
         
if (!preg_match('/^"(\\\\"|[^"])+"$/'str_replace("\\\\","",$local)))
         {
            
$isValid false;
         }
      }
      if (
$isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
      {
         
// domain not found in DNS
         
$isValid false;
      }
   }
   return 
$isValid;

In vielen aktuellen PHP-Versionen mit entsprechendem PEAR-Paket geht's auch so:

PHP Code:
<?php
$email 
"";

if(!
filter_var($emailFILTER_VALIDATE_EMAIL))
  {
  echo 
"E-mail is not valid";
  }
else
  {
  echo 
"E-mail is valid";
  }
?>
Whoknowsit is offline  
Thanks
1 User
Old 03/12/2012, 09:36   #3
 
JPGaming's Avatar
 
elite*gold: 169
Join Date: Jul 2011
Posts: 395
Received Thanks: 261
Schön, so viele Möglichkeiten zu sehen, aber ich versichere dir, dass

if(filter_var($email, FILTER_VALIDATE_EMAIL))

funktioniert, wie schon Whoknowsit geschrieben hat.
Mache ich auch so, und denke, einfacher geht es nicht.
JPGaming is offline  
Reply


Similar Threads Similar Threads
at&t syntax
09/21/2011 - General Coding - 8 Replies
hmmm... ich wusste zwar dass die at&t syntax (meiner meinung nach) nichts schönes is.... aber is die so anders? __asm("mov eax, fs:"); __asm("mov eax, "); __asm("mov edx, eax"); __asm("add eax, 0xeeeeeeee"); // platzhalter! __asm("push eax"); hier bekomm ich fehler für: mov eax, - too many memory references for 'mov' | invalid char ''
Syntax?
02/14/2011 - AutoIt - 26 Replies
Hey Leute, gibt es in diesem Programm, rein syntaktisch gesehen irgendwelche Fehler, weil Imagesearch, keins der Bilder identifizieren kann? Dim $myPics $myPics = 14 $myPics = '1.bmp' $myPics = '2.bmp' $myPics = '3.bmp' $myPics = '4.bmp' $myPics = '5.bmp'
[HELP] C# WPF syntax
12/23/2010 - CO2 Programming - 14 Replies
Does anyone knows how to convert or what's the right syntax on this C# form application syntax? webBrowser1.Document.GetElementById("name&quo t;).SetAttribute("value", textBox2.Text); webBrowser1.Document.GetElementById("message& quot;).SetAttribute("value", textBox1.Text); webBrowser1.Document.GetElementById("sumbit&q uot;).InvokeMember("click"); i'm having error on "GetElementById" :S just confused.
Überprüfen
11/02/2009 - Metin2 Private Server - 0 Replies
Moin com, wie kann man überfrüfen, was ein Char geschrieben und gemacht hat? lg soul



All times are GMT +1. The time now is 18:10.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.