ricardojlp
9/6/2015 - 5:15 PM

Regex validations

Regex validations

var regexValidations = {};

regexValidations = {
    checkIfValidEmailWithObj:function ($obj_element) {
        var bol_return = true,
            exp_regExp = /^$|^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(?:[a-zA-Z]{2,5})$/;

        if (!exp_regExp.test($obj_element.val())) {
            bol_return = false;
        }

        return bol_return;
    },
    checkIfValidPhoneWithObj:function ($obj_element) {
        var exp_regExp = /^$|^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]+[0-9\)]$/,
            bol_return = true;

        if (!exp_regExp.test($obj_element.val())) {
            bol_submitForm = false;
            bol_return = false;
        }

        return bol_return;
    },
    checkIfFutureWithObj:function ($obj_element) {
        var bol_return = false,
            dat_limit = new Date(),
            dat_user;

        if (isNotEmptyWithObj($obj_element)) {
            if ($obj_element.val().length <= 15) {
                $obj_element.val($obj_element.val().substring(0, 10));
            }

            dat_user = Date.parse($obj_element.val()).clearTime();

            dat_limit.setDate(dat_limit.getDate() - 1);

            if (dat_limit.compareTo(dat_user) == -1) {
                $obj_element.parents("fieldset.DateTime, fieldset.Date").removeClass("invalidDate");
                bol_return = true;
            }
            else {
                $obj_element.parents("fieldset.DateTime, fieldset.Date").addClass("invalidDate");
                bol_submitForm = false;
            }
        }
        return(bol_return);
    },
    isNotEmptyWithObj:function ($obj_element, bol_required) {

        if ($obj_element.val() == '' || $obj_element.val() == $obj_element.attr("placeholder")) {
            if (bol_required) bol_submitForm = false;
            return false;
        }
        else {
            return true;
        }
    },
    isNumberKey:function (evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && charCode != 43 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }
};