﻿
// validate if a textbox value satisfy the regex in "re"
function validateNumberTextBox(re, tb, errorLbl, errorMsg, allowEmpty) {
    var textbox = document.getElementById(tb);
    var errorDisplay = document.getElementById(errorLbl);
   
    if (!allowEmpty) {
        var inputVal = textbox.value;
        if (!inputVal) {
            errorDisplay.innerHTML = "<img src='images/unchecked.gif' alt=''/>&nbsp;This value cannot be empty";
            return false;
        }
    }

    if (!(re.test(inputVal))) {
        errorDisplay.innerHTML = "<img src='images/unchecked.gif' alt=''/>&nbsp;" + errorMsg;
        return false;
    }

    errorDisplay.innerHTML = "";
    return true;
}

// validate if a textbox value is empty
function validateNonEmptyTextBox(tb, errorLbl) {
    var textbox = document.getElementById(tb);
    var errorDisplay = document.getElementById(errorLbl);

    var inputVal = textbox.value;
    if (!inputVal) {
        errorDisplay.innerHTML = "<img src='images/unchecked.gif' alt=''/>&nbsp;This value cannot be empty";
        return false;
    }

    errorDisplay.innerHTML = "";
    return true;
}
