Validation for blank field in javascript

Here is the code for validate text box for not to be leave blank it pop up a message box when user leave field blank 'The required field has not been filled in' just copy and paste this code and pass the parameter that is id of text box.



function check_blank(tbId) {
    var tbObj = document.getElementById(tbId);
    if (tbObj.value.length == 0 || tbObj.value.charAt(0) == " ") {
        alert("The required field has not been filled in");
        return false;
    }
}
     

Popular Posts