Useful  php snippets for check valid data

All are Usefull php snippets...in here all snippets are use for check valid data or not. valid email,valid url,valid password,valid character,valid image,valid pdf all are php snippets

PHP SNIPPETS

##############################################################
# Function Use :This Function Used to valid 
##############################################################

function isValidEmail($email) {
    if ([email protected]("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email)) {
        return false;
    } else {
        return true;
    }
}

function isValidCapitalAlphaChar($text) {
    if (!eregi("^[A-Z]", $text)) {
        return false;
    } else {
        return true;
    }
}

function isValidAlphaChar($text) {
    if (!eregi("^[A-Za-z]", $text)) {
        return false;
    } else {
        return true;
    }
}

function isValidAlphaNumericChar($text) {
    if (!eregi("^[A-Za-z0-9]", $text)) {
        return false;
    } else {
        return true;
    }
}

function isVaildPassword($pass_text, $mini_len = "6", $max_len = "25") {
    if (strlen($pass_text) < $mini_len || strlen($pass_text) > $max_len) {
        $text = "Password must be between " . $mini_len . " to " . $max_len . " character";
    } else {
        for ($i = 0; $i < strlen($pass_text); $i++) {
            if (ord($pass_text[$i]) == '32')
                $ord = "improper";
        }
        if ($ord == "improper") {
            $text = "Please enter password properly.";
        }
    }

    return $text;
}

function isValidHttpURL($url) {
    if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) {
        return false;
    } else {
        return true;
    }
}

function isValidURL($url) {
    $regex = "((https?|ftp)://)?"; // SCHEME
    $regex .= "([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?"; // User and Pass
    $regex .= "([a-z0-9-.]*).([a-z]{2,3})"; // Host or IP
    $regex .= "(:[0-9]{2,5})?"; // Port
    $regex .= "(/([a-z0-9+$_-].?)+)*/?"; // Path
    $regex .= "(?[a-z+&$_.-][a-z0-9;:@&%=+/$_.-]*)?"; // GET Query
    $regex .= "(#[a-z_.-][a-z0-9+$_.-]*)?";

    if (!preg_match("/^$regex$/", $url)) {
        return false;
    } else {
        return true;
    }
}

function isValidImage($file_name) {

    $ext = strtolower(end(explode('.', $file_name)));
    if ($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "tif") {
        return true;
    } else {
        return false;
    }
}

function isValidPDF($file_name) {

    //echo $file_name;
    //exit;
    $ext = strtolower(end(explode('.', $file_name)));
    if ($ext == "pdf") {
        return true;
    } else {
        return false;
    }
}

function isValidCV($file_name) {

    $ext = strtolower(end(explode('.', $file_name)));
    if ($ext == "doc" || $ext == "docx" || $ext == "pdf") {
        return true;
    } else {
        return false;
    }
}

function isValidPPT($file_name) {
    $ext = strtolower(end(explode('.', $file_name)));
    if ($ext == "ppt" || $ext == "pptx") {
        return true;
    } else {
        return false;
    }
}

About The Massive Technolab

Avatar
Who We Are

Massive Technolab is a Leading IT services Company in India that expertise in web Development, Web Design and SEO at affordable rates.

Leave a Comment

comments powered by Disqus