<?php
class vlaidate
{
private $_error = array();
function vlaidateEmail($email,$name)
{
$trimed = trim($email);
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,8})$", $trimed))
{
$this->_error[$name] = $name.' Is not formated Correctly';
return false;
}
}
function vlaidateNumeric($num,$name)
{
$trimed = trim($num);
if (!is_numeric($trimed))
{
$this->_error[$name] = $name.' is not numeric';
}
else
{
return true;
}
}
function vlaidateTextOnly($text,$name)
{
$trimed = trim($text);
if (preg_match("/\d/", $trimed))
{
$this->_error[$name] = $name.' is not only text it includes numeric charcters';
return false;
}
}
function vlaidatePhonenumber($num,$name)
{
$trimed = trim($num);
if (!is_numeric($trimed)) {
$this->_error[$name] = $name.' is not numeric';
} else {
if ((strlen($trimed) < 10) || (strlen($trimed) > 10))
{
$this->_error[$name] = $name.'is not a vlaid Phone Number';
}
}
}
function strLenght($text,$name,$min = 0,$max)
{
$newtext = trim($text);
$strlength = strlen($newtext);
if ($strlength > $max)
{
$this->_error[$name] = $name.' should only be '.$max.' characters long';
return false;
} elseif ($strlength <= $min) {
$this->_error[$name] = $name.' is not long enough';
return false;
}
}
function removeHTML($text,$name)
{
$trimed = trim($text);
$newtext = strip_tags($trimed);
if (empty($newtext))
{
$this->_error[$name] = $name.' is empty';
return false;
}
else
{
return $newtext;
}
}
function getError()
{
return $this->_error;
}
}
//Class AD
class ad extends vlaidate
{
private $_title;
private $_summary;
private $_description;
private $_seller;
function __construct()
{
//Defeine Constants for Title Lenghts
define('TITLE_LENGTH_MIN',0);
define('TITLE_LENGTH_MAX',10);
//Define Constants for Summary Lenghts
define('SUMMARY_LENGTH_MIN',0);
define('SUMMARY_LENGTH_MAX',100);
}
function setTitle($title)
{
$this->_title = $title;
$this->strLenght($this->_title,'Title',TITLE_LENGTH_MIN,TITLE_LENGTH_MAX);
}
function setSummary($summary)
{
$this->_summary = $summary;
$this->strLenght($summary,'Summary',SUMMARY_LENGTH_MIN,SUMMARY_LENGTH_MAX);
}
function setDescription($description)
{
$this->_description = $description;
}
function setSeller($seller)
{
$this->_seller = $seller;
}
function getTitle ()
{
return $this->_title;
}
function getSummary()
{
return $this->_summary;
}
function getDescription()
{
return $this->_description;
}
function getSeller()
{
return $this->_seller;
}
}
$ad = new ad();
$ad->setTitle('Title');
$ad->setSummary('Hello This is a great car i dont k');
$ad->vlaidateEmail('vbabiy@youthlounge.com','Eamil');
$ad->vlaidatePhonenumber('5188783299','Home Phonenumber');
$ad->vlaidateTextOnly('asfasfsdfsd','TEST');
$ad->removeHTML('<h1>afslfjksla</h1>','HTML');
print_r($ad->getError());
?>
Learning OOP and hoping some on can give me some in site on how to even make these class better(more Secure, MORE OOP style... Any thing)