Various validation class
Created by Jose Chafardet, last update on 30/10/2008 11:37
This is yet again a small class i wrote (still working on it) that validates some input data (not perfect tho, i know, but im still working on it).
//==================
// Define class name
class Validation {
//===========
// Properties
//==================
// Public properties
public $str;
public $length;
//========
// Methods
//============================
// Public method alpha_numeric
public function alpha_numeric($str, $length) {
return false;
}
if (strlen ( $str ) <
$length) { return false;
}
return (!
preg_match ( "/^([-a-z0-9])+$/i",
$str )) ?
FALSE :
TRUE;
} // end public method alpha_numeric
//======================================================
// Public method valid_email
// validates to accept only valid email addresses,
// requiring an @ a . and at the very least 2 TLD leters
public function valid_email($str) {
return false;
}
return (!
preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix",
$str )) ?
FALSE :
TRUE;
} // end public method valid_email
//========================================
// Public method numeric
// validates to accept only numeric values
public function numeric($str, $length) {
return false;
}
if (strlen ( $str ) <
$length) { return false;
}
return (!
preg_match ( "/^([0-9])+$/i",
$str )) ?
FALSE :
TRUE;
} // end public method numeric
//========================================
// public method latin_chars
public function latin_chars($str) {
"&" => "&",
"á" => "",
"Â" => "",
"â" => "",
"Æ" => "",
"æ" => "",
"À" => "",
"à" => "",
"Å" => "",
"å" => "",
"Ã" => "",
"ã" => "",
"Ä" => "",
"ä" => "",
"Ç" => "",
"ç" => "",
"É" => "",
"é" => "",
"Ê" => "",
"ê" => "",
"È" => "",
"í" => "",
"Í" => "",
"ó" => "",
"Ó" => "",
"ö" => "",
"ú" => "",
"Ú" => "",
"û" => "",
"Ù" => "",
"ù" => "",
"Ü" => "",
"ü" => "",
"Ý" => "",
"ý" => "",
"ÿ" => "",
"Ÿ" => "Ÿ",
"ñ" => "",
"Ñ" => "",
);
foreach ($html_entities as $key => $value) {
}// end foreach
return $str;
} // end public method latin_chars
//=============================
// Public method sanitize_mysql
// sanitize data input
public function sanitize($str) {
return $str;
} // end public method sanitize_mysql
} // end class
Dependencies
No special requirements are needed by this snippet
By logging in you will be able to:
- Recommand this page to someone else
- Monitor changes on this item
- Rate this item
- Post comments
- Download this item
Login now!