Check valid md5 string in PHP


<?php
$md5 = 'd67c5cbf5b01c9f91932e3b8def5e5f8';
$flag = Check_Valid_Md5_String($md5);
if ($flag){ // flag true means string is a valid md5 encrypation
echo 'valid md5 string';
}else{
echo 'invalid md5 string or empty string';
}

//this function will check the string
function Check_Valid_Md5_String($md5=''){
if(empty($md5)) return false;
return preg_match('/^[a-f0-9]{32}$/', $md5);
}
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s