XoopsModules25x/smallworld

View on GitHub
assets/js/jquery.validation.functions.js

Summary

Maintainability
A
2 hrs
Test Coverage
/**
 * @author GeekTantra
 * @date 24 September 2009
 */

/*
 * This functions checks where an entered date is valid or not.
 * It also works for leap year feb 29ths.
 * @year: The Year entered in a date
 * @month: The Month entered in a date
 * @day: The Day entered in a date
 */
function isValidDate(year, month, day) {
    var date = new Date(year, (month - 1), day);
    var DateYear = date.getFullYear();
    var DateMonth = date.getMonth();
    var DateDay = date.getDate();
    if (DateYear == year && DateMonth == (month - 1) && DateDay == day)
        return true;
    else
        return false;
}

/*
 * This function checks if there is at-least one element checked in a group of check-boxes or radio buttons.
 * @id: The ID of the check-box or radio-button group
 */
function isChecked(id) {
    var ReturnVal = false;
    xoops_smallworld("#" + id).find('input[type="radio"]').each(function () {
        if (xoops_smallworld(this).is(":checked"))
            ReturnVal = true;
    });
    xoops_smallworld("#" + id).find('input[type="checkbox"]').each(function () {
        if (xoops_smallworld(this).is(":checked"))
            ReturnVal = true;
    });
    return ReturnVal;
}

/*
 * Function to test weather a url is a true website domain or not
 * Checks only full urls
 * Don't exactely remember where I found it.
 *
 */
function urlCheck(url) {
    var string = new RegExp();
    string.compile("^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$");
    if (!string.test(url)) {
        return false;
    }
    return true;
}