Validate Email and Password Fields on Form Submit Event

Today, We want to share with you Validate Email and Password Fields on Form Submit Event in JavaScript.In this post we will show you javascript form validation example download, hear for email id validation in javascript without regular expression we will give you demo and example for implement.In this post, we will learn about how to validate username and password in javascript from database with an example.

Validate Email and Password Fields on Form Submit Event in JavaScript

There are the Following The simple About javascript onsubmit form validation Full Information With Example and source code.

As I will cover this Post with live Working example to develop form validation using javascript code, so the JavaScript Onsubmit Event with form validation is used for this example is following below.

How to validate Empty Form Field?

function CheckEmpty(paramdata,inpTxt)
{
    objectvalue = paramdata.value.length;
    if(objectvalue=="")
    {
        alert("Oops.. Please fill out the value of "+inpTxt);
        paramdata.style.background = 'pink';
        return false;
    }
    else
        return true;
}

How to Validate Email Address via JavaScript?

function is_validate_email(field,alerttxt)
{
    with (field)
    {
        apos=value.indexOf("@");
        dotpos=value.lastIndexOf(".");
        if (apos<1||dotpos-apos<2){
            alert(alerttxt);return false;
        }
        else {
            return true;
        }
    }
}

How to Validate Password Field via JavaScript?

function validatePassword(inpTxt) {
    var displayErrMsg = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers
 
    if (inpTxt.value == "") {
        inpTxt.style.background = 'pink';
        displayErrMsg = "You didn't enter a password.\n";
        alert(displayErrMsg);
        return false;
 
    } else if ((inpTxt.value.length < 7) || (inpTxt.value.length > 15)) {
        displayErrMsg = "Your password is the wrong length. \n";
        inpTxt.style.background = 'pink';
        alert(displayErrMsg);
        return false;
 
    } else if (illegalChars.test(inpTxt.value)) {
        displayErrMsg = "Your password contains illegal characters.\n";
        inpTxt.style.background = 'pink';
        alert(displayErrMsg);
        return false;
 
    } else if ( (inpTxt.value.search(/[a-zA-Z]+/)==-1) || (inpTxt.value.search(/[0-9]+/)==-1) ) {
        displayErrMsg = "Your password must contain at least one numeral.\n";
        inpTxt.style.background = 'pink';
        alert(displayErrMsg);
        return false;
 
    } else {
        inpTxt.style.background = 'White';
    }
   return true;
}
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about password validation in javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment