Location: PHPKode > projects > phpCAMALEO > common/fun2inc/form_validation.inc
<?php
include_once($_SESSION[common].'fun2inc/form_errors.inc');
include_once($_SESSION[common].'fun2inc/validate_email.inc');

if(!function_exists('account_namevalid'))
{
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	# Validate account name
	#
	function account_namevalid($temp)
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	{	
		#	Must include only allowed characters
		#
		if(strspn($temp,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.")!=strlen($temp)) { return false; }
		#
		#	Illegal names
		#
		if(eregi("^((&#39;)|(or)|(root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news))$",$temp))	{ return false; }
		if(eregi("^((uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)|(www)|(cvs)|(shell)|(ftp))$",$temp))	{ return false; }
		if(eregi("^((irc)|(debian)|(ns)|(download)|(anoncvs_)|(xmail)|(&times;mail)|(system))$",$temp)) 			{ return false; }
		return true;
	}
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	# Validate date
	#
	#		Input date format pending on $flag:
	#
	#			$flag = 'ymd' => YYYY-MM-DD
	#			$flag = 'dmy' => DD-MM-YYYY
	#
	#			$flag = 'ymdl' => YYYY-MONTH-DD
	#			$flag = 'dmyl' => DD-MONTH-YYYY
	#
	function validate_date($date,$flag='ymd')
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	{
		include($_SESSION[common].'db/Globals.inc');
		switch($flag)
		{
			case 'ymdl':
				include($_SESSION[common].'includes/set_month_ary.php');
				$opt_mm	=array_flip($opt_mm);
				$dd		=substr($date,strlen($date)-2,strlen($date));
				$mml	=substr($date,5,strlen($date)-8);
				$mm		=$opt_mm[$mml];
				$yy		=substr($date,0,4);
				break;

			case 'dmyl':
				include($_SESSION[common].'includes/set_month_ary.php');
				$opt_mm	=array_flip($opt_mm);
				$dd		=substr($date,0,2);
				$mml	=substr($date,3,strlen($date)-8);
				$mm		=$opt_mm[$mml];
				$yy		=substr($date,strlen($date)-4,strlen($date));
				break;

			case 'ymd':	$dd=substr($date,8,2); $mm=substr($date,5,2); $yy=substr($date,0,4); break;
			case 'dmy': $dd=substr($date,0,2); $mm=substr($date,3,2); $yy=substr($date,6,4); break;
		}
		if(strspn($dd,'0123456789')!=strlen($dd)) { $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1019]); return($feedback); }
		if(strspn($mm,'0123456789')!=strlen($mm)) { $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1019]); return($feedback); }
		if(strspn($yy,'0123456789')!=strlen($yy)) { $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1019]); return($feedback); }
		if($mm=='04' || $mm=='06' || $mm=='09' || $mm=='11')
		{
			if($dd>'30') { $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1020]); return($feedback); }
		}
		if($mm=='02')
		{
			$temp1=$yy/4; $leap=is_int($temp1);
			if($leap  && $dd>'29')	{ $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1020]); return($feedback); }
			if(!$leap && $dd>'28')	{ $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1020]); return($feedback); }
		}
		if($dd<'1')		{ $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1020]); return($feedback); }
		if($dd>'31')	{ $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1020]); return($feedback); }
		if($mm<'1')		{ $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1021]); return($feedback); }
		if($mm>'12')	{ $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1021]); return($feedback); }
		if($yy<'1')		{ $feedback=BuildErrorString('<b>'.$dd.'-'.$mm.'-'.$yy.'</b>: '.$error_msg[1023]); return($feedback); }
		return('valid');
	}
}
?>
Return current item: phpCAMALEO