Location: PHPKode > scripts > Verification > verification/verification.php
<?php
class verification{
	/**
	 * RFC compatible function that checks formulation of email addresses
	 *
	 * @link http://www.ilovejackdaniels.com/php/email-address-validation/
	 * @param string $email
	 * @return boolean
	 */
	public function email($email) {
		//if it pass this simple test, we accept the email, else we do some extra testing
		//better 1 extra line of code once in awhile, than lots of code always.
		if (eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $email))
			return true;
		// First, we check that there's one @ symbol, and that the lengths are right
		if (!ereg('^[^@]{1,64}@[^@]{1,255}$', $email)) {
			// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
			return false;
		}
		// Split it into sections to make life easier
		$email_array = explode('@', $email);
		$local_array = explode('.', $email_array[0]);
		for ($i = 0; $i < sizeof($local_array); $i++) {
			if (!ereg('^(([A-Za-z0-9!#$%&\'*+/=?^_`{|}~-][A-Za-z0-9!#$%&\'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|")]{0,62}"))$', $local_array[$i])) {
				return false;
			}
		}
		if (!ereg('^\[?[0-9\.]+\]?$', $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
			$domain_array = explode('.', $email_array[1]);
			if (sizeof($domain_array) < 2) {
				return false; // Not enough parts to domain
			}
			for ($i = 0; $i < sizeof($domain_array); $i++) {
				if (!ereg('^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$', $domain_array[$i])) {
					return false;
				}
			}
		}
		return true;
	}
	public function url($url){
		$protocol	= '([[:alpha:]]+:\/\/)+';
		$domain		= '([[:alpha:]][-[:alnum:]]*[[:alnum:]])(\.[[:alpha:]][-[:alnum:]]*[[:alpha:]])+';
		$dir		= '(/[[:alpha:]][-[:alnum:]]*[[:alnum:]])*';
		$page		= '(/[[:alpha:]][-[:alnum:]]*\.[[:alpha:]]{3,5})?';
		$getstring	= '(\?([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+)(&([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+))*)?';
		$pattern	= '^'.$protocol.$domain.$dir.$page.$getstring.'$';
		return eregi($pattern, $url);
	}
	public function alphanum($string){
		$allowchars = 'abcdefghijklmnopqrstuvwxyz0123456789_';
		return !(strspn(strtolower($string),$allowchars)==0);
	}
	public function numeric($number){
		return is_numeric($number);
	}
	public function string($string){
		return is_string($string) && $string!='';
	}
	public function text($string){
		return $this->string($string);
	}
	public function phone($phone){
		$phone = ereg_replace( '[^0-9]', '', $phone);
		return (is_numeric($phone) && strlen($phone)>=7);
	}
	public function ip_address($checkip, $jolly_char='') {
		if ($jolly_char=='.')        // dot ins't allowed as jolly char
			$jolly_char = '';
		
		if ($jolly_char!='') {
			$checkip = str_replace($jolly_char, '*', $checkip);        // replace the jolly char with an asterisc
			$my_reg_expr = '^[0-9\*]{1,3}\.[0-9\*]{1,3}\.[0-9\*]{1,3}\.[0-9\*]{1,3}$';
			$jolly_char = '*';
		}else{
			$my_reg_expr = '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$';
		}
		
		if (eregi($my_reg_expr, $checkip)) {
			for ($i = 1; $i <= 3; $i++) {
				if (!(substr($checkip, 0, strpos($checkip, '.')) >= '0' && substr($checkip, 0, strpos($checkip, '.')) <= '255')) {
					if ($jolly_char!='') {            // if exists, check for the jolly char
						if (substr($checkip, 0, strpos($checkip, '.'))!=$jolly_char){
							return false;
						}
					}else{
						return false;
					}
				}
				$checkip = substr($checkip, strpos($checkip, '.') + 1);
			}
		
			if (!($checkip >= '0' && $checkip <= '255')) {        // class D
				if ($jolly_char!='') {            // if exists, check for the jolly char
					if ($checkip!=$jolly_char){
						return false;
					}
				}else{
					return false;
				}
			}
		}else{
			return false;
		}
		
		return true;
	}
//	public function credit_card($card_number){
//	}
}
?>
Return current item: Verification