PHP Classes

File: examples/factories/SanitizerEmail.php

Recommend this page to a friend!
  Classes of Leo Daidone   PHP Sanitize Class   examples/factories/SanitizerEmail.php   Download  
File: examples/factories/SanitizerEmail.php
Role: Example script
Content type: text/plain
Description: Example Sanitizer
Class: PHP Sanitize Class
Validate and sanitize string values
Author: By
Last change: Update of examples/factories/SanitizerEmail.php
Date: 9 months ago
Size: 915 bytes
 

Contents

Class file image Download
<?php
/**
 * Created by PhpStorm.
 * User: leodaido
 * Date: 1/19/15
 * Time: 6:39 PM
 */

require_once(dirname(__FILE__).'/../../factories/AbstractSanitizer.php');
require_once(
dirname(__FILE__).'/../../factories/ISanitizer.php');

class
SanitizerEmail extends AbstractSanitizer implements ISanitizer{
    private
$pattern = "/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/";
    private
$pattern_replace = "/[\;\#\n\r\*\'\"<>&\%\!\(\)\{\}\[\]\?\\/\s,]/";
    private
$replacement = "";

    public function
validate($string){
        return
preg_match($this->pattern, $string);
    }

    public function
cleanup($email){
       
$email = trim($email);
       
$email = str_replace(" ", "", $email);
        if(
count(explode('@',$email))>2){
            throw new
Exception('Invalid email address');
        }
        return
preg_replace($this->pattern_replace, $this->replacement, $email);
    }
}