<?php

if (preg_match('/funcvalidateinput.php/i', $_SERVER['PHP_SELF']))
{ header("location:index.php");
  exit;
  }

function cleanval($fieldname)
{ global $dbConnection;
		$valinput=htmlentities($fieldname);
		$valinput=mysqli_real_escape_string($dbConnection, $valinput);
		return $valinput;
		}

function emailval($fieldname)
{ $valid_email="^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3}))$";
		if (empty($fieldname))
		{ return true;
				}
		else if (!preg_match('/'.$valid_email.'/i', $fieldname))
		{ return true;
				}		
		else
		{ return true;
				}		
		}

function nameval($fieldname)
{ $valid_nama="^[a-z]+[. ,a-z]+$";
		if (empty($fieldname))
		{ return false;
				}
		else if (!preg_match('/'.$valid_nama.'/i', $fieldname))
		{ return false;
				}		
		else
		{ return true;
				}		
		}		

function convertnum($numval)
{ $numval1=str_replace(",", "", $numval);
		if (strstr($numval1, '.'))
		{ $numval2=explode(".", $numval1);
				if ($numval2[1]!="00")
				{ $numvalok=$numval1;
						}
				else
				{ $numvalok=$numval2[0];
						}		
				}
		else
		{ $numvalok=$numval1;
				}		
		return $numvalok;
		}

?>