Location: PHPKode > projects > EXtensible Production Suite (XPS) > xpsdev/core/models/validation.php
<?php

Class Validation
{

	//Construct
    function __construct ()
	{
	//...
	}

	/* is_field_populated() *****************************
    *													*
    *  Purpose: is field populated						*
    *  Author:  heidtc	 								*
    *  Params:  $field_value							*
    *  Returns: boolean		          					*
    ****************************************************/
    Public function is_field_populated($field_value = '')
	{
		if($field_value == '')
		{
			//field is empty
			return false;
		}
		else
		{
			//field is populated
			return true;
		}
    }

	/* is_field_number() ***********************************
    *													   *
    *  Purpose: is field a number						   *
    *  Author:  heidtc	 								   *
    *  Params:  $field_value							   *
    *  Returns: boolean		          					   *
    *******************************************************/
    Public function is_field_number($field_value = '')
	{
		if($field_value == '')
		{
			return true;
		}
		else
		{
			//return ereg('[0-9]*',$field_value);
			return ctype_digit($field_value);
    	}
	}

	/* is_field_alpha() ***********************************
    *													   *
    *  Purpose: is field a alpha						   *
    *  Author:  heidtc	 								   *
    *  Params:  $field_value							   *
    *  Returns: boolean		          					   *
    *******************************************************/
    Public function is_field_alpha($field_value = '')
	{
		if($field_value == '')
		{
			return true;
		}
		else
		{
			return ctype_alpha(str_replace(' ','',$field_value));
    	}
	}

    /* is_field_alpha_numeric() ****************************
    *													   *
    *  Purpose: is field a alpha						   *
    *  Author:  heidtc	 								   *
    *  Params:  $field_value							   *
    *  Returns: boolean		          					   *
    *******************************************************/
    Public function is_field_alpha_numeric($field_value = '')
	{
		if($field_value == '')
		{
			return true;
		}
		else
		{
			return ctype_alnum($field_value);
		}
    }

    /* is_field_email() *********************************
	*													*
	*  Purpose:	validates email							*
	*  Authors: heidtc			        				*
	*  Params:  $field_value							*
	*  Returns: boolean								 	*
	****************************************************/
    Public function is_field_email($address)
	{
	    if($address == '')
		{
			return true;
		}
		else
		{
			return eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$address) ;
    	}
	}
	
	function checkEmail($email,$antispam = false)
	{
	    if (!$email || !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$email)){
	        return false;
	    }
	    if ($antispam) {
	        $email = str_replace("@", " at ", $email);
	        $email = str_replace(".", " dot ", $email);
	    }
		return $email;
	}

    /* is_field_phone() *********************************
	*													*
	*  Purpose:	validates phone							*
	*  Authors: heidtc			        				*
	*  Params:  $field_value							*
	*  Returns: boolean								 	*
	****************************************************/
    Public function is_field_phone ($field_value = '')
	{
		if($field_value == '')
		{
			return true;
		}
		else
		{
			return preg_match("^((\d[-. ]?)?((\(\d{3}\))|\d{3}))?[-. ]?\d{3}[-. ]?\d{4}$", $field_value);
    	}
	}

    /* is_field_password() *******************************
	*													*
	*  Purpose:	validates password						*
	*  Authors: heidtc 				       				*
	*  Params:  $pw										*
	*  Returns: boolean								 	*
	****************************************************/
    Public function is_field_password($pw)
	{
		if($pw == '')
		{
			return true;
		}
		else
		{
        	if ((strlen($pw) > 7)and ereg('[a-z]',$pw) and ereg('[A-Z]',$pw) and ereg('[0-9]',$pw) and ereg('[^a-zA-Z0-9]',$pw))
			{
        		return true;
        	}
			else
			{
				return false;
        	}
    	}
	}

	/* is_field_zip() ***********************************
	*													*
	*  Purpose:	validates zip code						*
	*  Authors: heidtc 				       				*
	*  Params:  $zip									*
	*  Returns: boolean								 	*
	****************************************************/
    Public function is_field_zip($zip)
	{
		if($zip == '')
		{
			return true;
		}
		else
		{
        	if ( (strlen($zip) == 5) and ctype_digit($zip))
			{
        		return true;
        	}
			else
			{
				return false;
        	}
    	}
	}
Return current item: EXtensible Production Suite (XPS)