<?php
ini_set('display_errors',1);



//Date or Birth Y-m-d
function CheckDob($x) {
    if(isset($x) and preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$x)) {
        return true;
    } else return false;
}

//username validation 5 english chars & letters
function CheckUniqueUsername($x) {
    if(isset($x) and preg_match("/^[a-z]\w{2,23}[^_]$/", $x)) {
        return true;
    } else return false;
}


//adress validation
function CheckAddressValidation($x) {
    if(isset($x) and preg_match('/^[a-zA-Z0-9\s\-,.\/#@()&]+$/u', $x)) {
        return true;
    } else return false;
}

//Comapny pan Validation
function CheckCompanyPanValidtion($x) {
    if(isset($x) and preg_match("/^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/", $x)) {
        return true;
    } else return false;
}


//Branch GST Validation
function BranchGstValidation($x) {
    if(isset($x) and preg_match("/^[a-zA-Z0-9]{5,16}$/", $x)) {
        return true;
    } else return false;
}

//Pin Code Validation
//PIN code doesn't start from zero
//Allows 6 digits only
//Allows 6 consecutive digits (e.g. 431602)
//Allows 1 space after 3 digits (e.g. 431 602)//
function PinCodeValidation($x) {
    if(isset($x) and preg_match("([1-9]{1}[0-9]{5}|[1-9]{1}[0-9]{3}\\s[0-9]{3})", $x)) {
        return true;
    } else return false;
}

//Is numeric
function IsNumeric($x) {
    if(isset($x) and preg_match("/^[1-9][0-9]*$/", $x)) {
        return true;
    } else return false;
}

//validating-24-hour-time-format
function CheckValidateTime($x) {
    if(isset($x) and preg_match("#^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$#", $x)) {
        return true;
    } else return false;
}

//validating-24-hour-time-format
function CheckAlphabetssWithSpace($x) {
    if(isset($x) and preg_match("/^[a-zA-Z ]*$/", $x)) {
        return true;
    } else return false;
}

//validating-24-hour-time-format
function CheckAlphabetssWithSpaceNumeric($x) {
    if(isset($x) and preg_match("/^[a-zA-Z ]*$/", $x)) {
        return true;
    } else return false;
}
//Start date and end date validation
function CheckStartDate($x) {
    if(isset($x) and preg_match("/^[0-9]{4}(-|\/)([1-9]|0[1-9]|1[0-2])(-|\/)([1-9]|0[1-9]|[1-2][0-9]|3[0-1])$/", $x)) {
        return true;
    } else return false;
}

// should only allow alphabets
function checkOnlyCharacters($x) {
     if(isset($x) and preg_match ("/^[a-zA-Z\s]+$/",$x)) {
        return true;
    } else return false;
}

function checkOnlyCharcterNumericwithSpace($x){
    if(isset($x) && preg_match("/^[A-Za-z0-9 ,\.\/-]*$/", $x)) {
        return true;
    } else {
        return false;
    }
}


function checkWebsiteUrl($x){
    
     if(isset($x) and preg_match("/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-
            ]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]
            \.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|w
            ww\.[a-zA-Z0-9]+\.[^\s]{2,})$/",$x)) {
        return true;
     } else return false;

    
}

//validating-24-hour-time-format
function CheckValidateSessionTime($x) {
    if(isset($x) and preg_match("/^([01]\d|2[0-3]):?([0-5]\d)$/", $x)) {
        return true;
    } else return false;
}

function CheckCode($x) {
    if(isset($x) and preg_match("/^[a-zA-Z0-9]{4,6}$/", $x)) {
        return true;
    } else return false;
}

function CheckDateValidation($date) {
   
    return date("d-m-Y",strtotime($date));

}

function validateAadhaar($aadhaar) {
    // Remove any non-numeric characters
    $aadhaar = preg_replace("/[^0-9]/", "", $aadhaar);

    // Check if the length is valid
    if (strlen($aadhaar) !== 12) {
        return false;
    }

    // Calculate the checksum
    $checksum = 0;
    for ($i = 0; $i < 11; $i++) {
        $digit = (int)$aadhaar[$i];
        $checksum += ($digit * (12 - $i));
    }

    // Validate the checksum
    $remainder = $checksum % 11;
    $valid_checksum = (11 - $remainder) % 10;

    if ($valid_checksum !== (int)$aadhaar[11]) {
        return false;
    }

    // Passed all checks, Aadhaar number is valid
    return true;
}


function CheckUsername($x) {
    if(isset($x) and preg_match("/^[a-zA-Z0-9_@]*$/", $x)) {
        return true;
    } else return false;
}
function validateYouTubeUrl($x)
{
    if(isset($x) and preg_match("/^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+$/", $x)) {
        return true;
    } else return false;
}
?>