Create Validation Login

 

create validation on the login form

in the object, I have to add validation to the login form I created.

I created a form structure using (HTML).

HTML code:- (loginform.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
    <title>Document</title>
</head>
<body>
    <div class="container">
        <form id="form" action="#" class="form-login" >
            <div>
                <div class="input">
                    <input type="text" id="email" placeholder="Email or Phone Number">
                </div>
                <div id="emailerror">
                </div>
                <div class="input">
                    <input type="password" id="password" placeholder="Password">
                </div>
                <div id="passerror">
                 </div>
            </div>
            <div class="login-button" onclick="check_empty();">
                <button class="button"><b>Log In</b></button>
            </div>
            <div class="forget-account">
                <a href="#">Forget Password?</a>
            </div>
            <div class="hr"></div>
            <div class="create-account">
                <b>Create New Account</b>
            </div>
        </form>
    </div>

</body>
</html>


Second I create a stylesheet (style.css).

body{
    background#f0f2f5;
}
.container{
    margin100px auto;
    text-aligncenter;
    width396px;
    background#fff;
    border-radius8px;
    floatnone;
    color#1c1e21;
    padding-bottom24px;
    padding-top10px;
    box-shadow0 2px 4px rgb(0 0 0 / 10%), 0 8px 16px rgb(0 0 0 / 10%);
    

}
.form-login{
    margin0;
    padding0;
    displayblock;
}

div{
    displayblock;
}

input{
    background#fff;
    color#1c1e21;
    font-size17px;
    padding14px 16px;
    width330px;
    border-radius6px;
    border1px solid #dddfe2;
    color#1d2129;
    margin-top16px;
}


   




.button{
    background#1877f2;
    bordernone;
    border-radius6px;
    font-size22px;
    line-height48px;
    padding0 16px;
    width364px;
    cursorpointer;
    displayinline-block;
    text-decorationnone;
    white-spacenowrap;
    color#fff;
    margin-top16px;

}
.forget-account{
    margin-top16px;

}

.forget-account a{
    font-familyinherit;
    font-size14px;
    font-weight500;
    text-decorationnone;
    color#1877f2;


}

.hr{
    align-itemscenter;
    border-bottom1px solid #dadde1;
    displayflex;
    margin20px 16px;
    text-aligncenter;
}

.create-account{
    bordernone;
    border-radius6px;
    font-size17px;
    line-height48px;
    padding0 16px;
    displayinline-block;
    background#42b72a;
    color#fff;
}





#emailerror{
    color#f02849;
    font-family: SFProText-Regular, HelveticaArialsans-serif;
    font-size13px;
    line-height16px;
    margin-top8px;
    text-alignleft;
    padding0 16px;

}
#emailerror a{
    align-itemscenter;
    
    color#f02849;
    font-family: SFProText-Regular, HelveticaArialsans-serif;
    text-decorationnone;
}
#passerror{
    color#f02849;
    font-family: SFProText-Regular, HelveticaArialsans-serif;
    font-size13px;
    line-height16px;
    margin-top8px;
    text-alignleft;
    padding0 16px;

}
#passerror a{
    align-itemscenter;
    
    color#f02849;
    font-family: SFProText-Regular, HelveticaArialsans-serif;
    text-decorationnone;
}


Third I create a script to validate login (script.js):-

function check_empty(){
    var txt = "";
    var email = document.getElementById("email").value;
    var password = document.getElementById("password").value;
    if (email == ""){
        txt = 'The email or mobile number you entered isn’t connected to an account. <a href="" ><b>Find your account and log in.</b></a>';
        document.getElementById('emailerror').innerHTML = txt;
    }
    if (password == ""){
        txt = 'The email or mobile number you entered isn’t connected to an account. <a href="" ><b>Find your account and log in.</b></a>';
        document.getElementById("passerror").innerHTML = txt;
    }


}


Thanks For Reading 

channel link :- https://www.youtube.com/channel/UC1DFWpD1k1PtxIzYbdBAj6g 

Add your comment 

Signature :- Ayoub Shindi (Dev AAS).

Comments