Input Validators in PHP

Source : http://www.openpeta.com

<?php
/*
* FileName:validation.php
* Created on Jan 16, 2007
* Author:Antony
*/
function validateUname($uname) {
if (ereg(’^[a-zA-Z0-9_]{3,50}$’, $uname))
return true;
else
return false;
}

function validatePassword($pwd) {
if (strlen($pwd) >= 6)
return true;
else
return false;
}

function validateEmail($email) {
if (eregi(’^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$’, $email))
return true;
else
return false;
}

function validateDate($date) {
if (ereg(’(^[0-9]{1,2})-[0-9]{1,2}-([0-9]{4}$)’, $date))
return true;
else
return false;
}

function validateMobile($mobile) {
if (ereg(’(^[+0-9]{1,3})*([0-9]{10,11}$)’, $mobile))
return true;
else
return false;
}

function validateUrl($url) {
if (ereg(’^[http://]+[www]*\.[0-9a-zA-Z_.]+\.[a-zA-Z.]{1,5}$’, $url))
return true;
else
return false;
}

function validatePin($pin) {
if (ereg(’^[0-9]{6}$’, $pin))
return true;
else
return false;
}
?>

Comments

Popular Posts