PHP Classes
elePHPant
Icontem

File: validate_address.class.php

Recommend this page to a friend!
  Classes of Sven Wagener  >  validation  >  validate_address.class.php  >  Download  
File: validate_address.class.php
Role: Class source
Content type: text/plain
Description: Validate address data
Class: validation
Validation with non-regular expression patterns
Author: By
Last change: Added function validate_phone_int for international phone numbers
Date: 15 years ago
Size: 2,091 bytes
 

 

Contents

Class file image Download
<?php
/**
* Validation class for validation of misc text
*
* @author Sven Wagener <wagener_at_indot_dot_de>
* @include Funktion:_include_
*/
include("validate.class.php");

class
validate_address extends validate{
    var
$country_code="";
   
    var
$pattern_postcode=array(
   
'at'=>'4N',
   
'au'=>'2-3N',
   
// 'ca'=>'^[a-zA-Z].[0-9].[a-zA-Z].\s[0-9].[a-zA-Z].[0-9].',
   
'de'=>'5N',
   
'ee'=>'5N',
   
'nl'=>'4N 2L',
   
'it'=>'5N',
   
'pt'=>'4N-3N',
       
'fi'=>'5N',
   
'se'=>'3N 2N',
   
// 'uk'=>'^([A-Z]{1,2}[0-9]{1}[0-9A-Z]{0,1}) ?([0-9]{1}[A-Z]{1,2})$',
   
'uk'=>'1-2LN0-1L',
   
'us'=>'5N0-1-4N'
   
);

    var
$pattern_email='^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$';

   
    function
validate_address($country="de"){
       
$this->country_code=$country;
    }
   
    function
validate_name($string){
       
$pattern="2-20L 2-20L0-1 0-20L0-1 0-20L";
       
$this->format($pattern);
        return
$this->check($string);
    }
   
    function
validate_street($string){
       
$pattern="0-30L0-1 0-20L0-1L0-1.1-3N";
       
$this->format($pattern);
        return
$this->check($string);
    }
   
    function
validate_postcode($string){
       
$pattern=$this->pattern_postcode[$this->country_code];
       
$this->format($pattern);
        return
$this->check($string);
    }
   
    function
validate_phone($string){
       
$pattern="3-6N-3-20N";
       
$this->format($pattern);
        return
$this->check($string);
    }

    function
validate_phone_int($string){
       
$pattern="4N-3-6N-3-20N";
       
$this->format($pattern);
        return
$this->check($string);
    }
    function
validate_fax($string){
        return
$this->validate_phone($string);
    }
   
    function
validate_mobile($string){
        return
$this->validate_phone($string);
    }
   
    function
validate_mail($string){
        return
ereg($this->pattern_email,$string);
    }
   
    function
validate_url($string){
        if(
$file=@fopen($string,"r")){
            return
true;
        }else{
            return
false;
        }
    }
   
    function
validate_ip($string){
       
$pattern="1-3N.1-3N.1-3N.1-3N";
       
$this->format($pattern);
        return
$this->check($string);
    }
}
?>