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.

Read Also:  javascript validation registration form

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 :

Read Also:  Angular 6 Introduction Tutorial features of angular 6.0

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  jquery password strength Checker using regular expression
  2. Read Also:  JavaScript Client side Password hashing and encryption
  3. Read Also:  Bootstrap get active tabs index using jQuery Example
  4. Read Also:  simple email validation in javascript
  5. Read Also:  jQuery Validate Email address using Regex Expression
  6. Read Also:  PHP Multiple Authentication using Laravel 5.7 Middleware
  7. Read Also:  jquery uncheck all checkboxes Multiple Checkbox Example
  8. Read Also:  PHP MYSQLi datetime format insert into mysql
  9. Read Also:  Get HTML source code of page with php - Scrape
  10. Read Also:  javascript Form validation Source code
CLOSEX