<?php 
session_start();
header('Content-Type: text/html; charset=UTF-8');
require('registriersystem.php');
if(isset($_POST['Registrieren'])){
    $vorname = $_POST["vorName"];
    $nachname = $_POST['nachName'];
    $strasse = $_POST['strasse'];
    $hausnummer = $_POST['hausnummer'];
    $plz = $_POST['postleitzahl'];
    $ort = $_POST['ort'];
    $emailrep = $_POST['emailRep'];
    $email = $_POST['email'];
    $passwort = $_POST['passwort'];
    $passwortrep = $_POST['passwortRep'];
    if(empty($vorname) || empty($nachname) || empty($strasse) || 
    empty($hausnummer) || empty($plz) || empty($ort) || 
    empty($emailrep) || empty($email) || empty($passwort) || empty($passwortrep))
    {  
       header("Location: registrierung_wiederholen.php");
        
    }elseif (!preg_match("/^[A-Za-zÄÖÜäöüß -]*$/", $vorname)
                || !preg_match("/.{2,}/", $vorname)
                || preg_match("/(?:([- ])\1{1,}|( -)|(- ))/", $vorname)
                || !preg_match("/^([A-ZÄÖÜa-zäöüß]{2,}[ -]?)+$/", $vorname)
                || !preg_match("/[a-zäöüß]$/", $vorname)
                || !preg_match("/^[A-ZÄÖÜ][a-zäöüß]+([- ][A-ZÄÖÜ][a-zäöüß]+)*$/", $vorname)
                || preg_match("/(\w)\1{2,}/", $vorname)) {
    
                    header("Location: registrierung_wiederholen.php");
   
    }elseif (!preg_match("/^[A-Za-zÄÖÜäöüß -]*$/", $nachname)
    || !preg_match("/.{2,}/", $nachname)
    || preg_match("/([-])\1{1,}/", $nachname)
    || !preg_match("/^([A-ZÄÖÜa-zäöüß]{2,}[ -]?)+$/", $nachname)
    || !preg_match("/[a-zäöüß]$/", $nachname)
    || preg_match("/[A-ZÄÖÜ][a-zäöüß]+[ ]+[A-ZÄÖÜ][a-zäöüß]+/", $nachname)
    || !preg_match("/^(von( der)?|zu|van)[ ][A-ZÄÖÜ]|^[A-ZÄÖÜ]/", $nachname)
    || !preg_match("/(^(von( der)?|zu|van)[ ][A-ZÄÖÜ][a-zäöüß]+|^[A-ZÄÖÜ][a-zäöüß]+)([-][A-ZÄÖÜ][a-zäöüß]+)?$/", $nachname)
    || preg_match("/(\w)\1{2,}/", $nachname)) {
        
        header("Location: registrierung_wiederholen.php");
       
    }elseif ( !preg_match("/.{2,}/", $strasse)
    || !preg_match("/^[^0-9]*$|[0-9]$/", $strasse)
    || !preg_match("/^[A-Za-z0-9ÄÖÜäöüß' -]+$/", $strasse)
    || !preg_match("/^[A-ZÄÖÜ][ -]?[a-zäöü0-9ß']+([ -]?[A-ZÄÖÜ0-9][A-Za-z0-9ÄÖÜäöüß']+)*$/", $strasse)
    || !preg_match("/[0-9]$|[a-zäöüß]$/", $strasse)) {
      
        header("Location: registrierung_wiederholen.php");
    }elseif ( !preg_match("/^[0-9]/", $hausnummer)
    || preg_match("/^0/", $hausnummer)
    || !preg_match("/^[1-9][0-9]{0,3}[a-z]?$/", $hausnummer)){
      
        header("Location: registrierung_wiederholen.php");
    }elseif ( !preg_match("/^(0100[1-9]|010[1-9][0-9]|01[1-9][0-9]{2}|0[2-9][0-9]{3}|[1-9][0-9]{4})$/", $plz)){
       
        header("Location: registrierung_wiederholen.php");
    }elseif ( !preg_match("/.{2,}/", $ort)
    || preg_match("/[ \/-][ \/-]/", $ort)
    || !preg_match("/^[A-ZÄÖÜa-zäöüß \/-]+$/", $ort)
    || preg_match("/(\w)\1{2,}/", $ort)
    || !preg_match("/^[A-ZÄÖÜ]/", $ort)
    || !preg_match("/[a-zäöüß]$/", $ort)
    || !preg_match("/^[A-ZÄÖÜ][a-zäöüß]+([ -\/][A-ZÄÖÜa-zäöü][a-zäöüß]+)*$/", $ort)){
      
        header("Location: registrierung_wiederholen.php");
    }elseif ( !preg_match("/[A-Za-z0-9_!#$%&'*+-\/=?^_`.{|}~]+[@][A-Za-z0-9-]+[.][A-Za-z]{2,}/", $email)){
       
        header("Location: registrierung_wiederholen.php");
    }elseif($email != $emailrep){
     
        header("Location: registrierung_wiederholen.php");
    }elseif (!preg_match("/^(?=.*[A-ZÄÖÜ])(?=.*[a-zäöüß])(?=.*[0-9])(?=.*[!°`´@#$%^&*()_+\-=\[\]{};':\"\\|,.<>\/?]).{6,}$/", $passwort)
    || !preg_match("/.{6,}/", $passwort)){
      
        header("Location: registrierung_wiederholen.php");
    }elseif($passwort != $passwortrep){
      
        header("Location: registrierung_wiederholen.php");
    }else{

      
        register($vorname,
        $nachname ,
        $email,
        $passwort, $strasse, $hausnummer, $ort, $plz);

        
        
    }

}
?>