Form Validation functions - PHP


Posted by vishnu on March 7, 2010, 1:49 pm
in My works ( Another geek from India)

Here are few functions in PHP to validate forms:



Validate Text:


CODE:


function validateText($input){
$result = ereg ("^[A-Za-z0-9\ ]+$", $input );
if ($result){
return true;
}else{
return false;
}
}





Validate Text Without spaces:


CODE:


function validateTextWithoutSpaces($input){
$result = ereg ("^[A-Za-z0-9]+$", $input );
if ($result){
return true;
}else{
return false;
}
}





Validate URL:



CODE:


function validateURL($url)
{
return preg_match("/^(http(s<img src="http://vishnus.name/blog/smilies/icon_question.gif" alt="?)" />:\/\/|ftp:\/\/{1})((\w+\.){1,})\w{2,}$/i", $url);







Validate Email:


CODE:


function validateEmail($mail){
$result = ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $mail );

if ($result){
return true;
}else{
return false;
}
         
}


Post from : http://vishnus.name/blog/index.php
Printed from : http://vishnus.name/blog/index.php?id=131