HomeCoding & Programming

PHP email validation function & file extension validation function

Like Tweet Pin it Share Share Email

Very easy and handy to use PHP email validation function and File type validation function/methods.

Email validation


<?php

/**
* Function for email validation
* @param string $email
* @return boolean
*/

function valid_email($email) {
$result = true;
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
$result = false;
}
return $result;
}

?>

Image File extension validation


<?php

/**
* Function for checking the image (by extension)
* @param string $file_name
* @return boolean
*/

function is_image_file($file_name)
{
$arr_img = explode('.',$file_name);
$image_extension = end($arr_img);
//    array of all the allowed extensions
$image_extensions_allowed =array('jpg','jpeg','png','gif','JPG','JPEG','PNG','GIF');
if(in_array($image_extension,$image_extensions_allowed)){
return true;
}else{
return false;
}
}

?>

read out some more ready to use PHP validation functions/methods.

Comments (1)

  • What’s up mates, you are sharing your feelings on the topic of blog Search engine optimisation, I am also new user of web, therefore I am also getting more from it. Thanks to all.

Comments are closed.