Code: Select all
<?php
class fieldschecker
{
// 4-30 min and max email length
// 4-30 min and max username length
// 6-30 min and max password length
// field_error stores every error occured
// breaker is just for the sake of new line in showing errors
public $field_error;
public $yeserror=0;
public $breaker="<br>";
private $maxemaillength=30;
private $minemaillength=4;
private $maxpasswordlength=30;
private $minpasswordlength=6;
private $maxusernamelength=30;
private $minusernamelength=3;
private $maxnamelength=30;
private $minnamelength=2;
private $maxnamelength=30;
private $minlastnamelength=2;
private $mainpassword;// For checking the second confirm password
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function namechecker($name)
{
if (strlen($name) <= $this->minnamelength)
{
$this->field_error.="Name length should be more than ".$this->minnamelength." characters.".$this->breaker;
$this->yeserror=1;
}
if (strlen($name) >= $this->maxnamelength)
{
$this->field_error.="Name length should be less than ".$this->maxnamelength." characters.".$this->breaker;
$this->yeserror=1;
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function lastnamechecker($lastname)
{
if (strlen($lastname) <= $this->minlastnamelength)
{
$this->field_error.="Last name length should be more than ".$this->minlastnamelength." characters.".$this->breaker;
$this->yeserror=1;
}
if (strlen($lastname) >= $this->maxlastnamelength)
{
$this->field_error.="Last name length should be less than ".$this->maxlastnamelength." characters.".$this->breaker;
$this->yeserror=1;
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function emailchecker ($email)
{
if (strlen($email) <= $this->minemaillength)
{
$this->field_error.="Email length should be more than ".$this->minemaillength." characters.".$this->breaker;
$this->yeserror=1;
}
if (strlen($email) >= $this->maxemaillength)
{
$this->field_error.="Email length should be less than ".$this->maxemaillength." characters.".$this->breaker;
$this->yeserror=1;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$this->field_error.="Please provide a proper email.".$this->breaker;
$this->yeserror=1;
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function passwordchecker($password)
{
$this->mainpassword=$password;
if (strlen($password) <= $this->minpasswordlength)
{
$this->field_error.="Password length should be more than ".$this->minpasswordlength." characters.".$this->breaker;
$this->yeserror=1;
}
if (strlen($password) >= $this->maxpasswordlength)
{
$this->field_error.="Email length should be less than ".$this->maxpasswordlength." characters.".$this->breaker;
$this->yeserror=1;
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function passwordrechecker($repassword)
{
if ($this->mainpassword != $repassword)
{
$this->field_error.="Password and Confirm Password should be same.".$this->breaker;
$this->yeserror=1;
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function usernamechecker($username)
{
if (strlen($username)<= $this->minusernamelength)
{
$this->field_error.="Username length should be more than ".$this->minusernamelength." characters.".$this->breaker;
}
if (strlen($username)>= $this->maxusernamelength)
{
$this->field_error.="Username length should be less than ".$this->maxusernamelength." characters.".$this->breaker;
}
}
}
?>