Hello friends, today we will be going to how do we create Login Form validation with Shake Effect Using Html CSS and JavaScript. I have posted many videos and articles before related to the JavaScript project, now this the something new that we are going to build.
Video Tutorial of How to create Login Form validation with Shake Effect
As you have seen on the given video tutorial of How to create Login Form validation with Shake Effect,
If you are feeling bored watching the given video tutorial of How to create Login Form validation with Shake Effect then you can copy or download the given codes below:
How to create Login Form validation with Shake Effect | Free Source Code
To create this program (Login Form validation with Shake Effect). First, you need to create two Files one HTML File and another one is CSS File. After creating these files just paste the following codes in your file.
In the first place, make a HTML document with the name of index.html and glue the given codes in your HTML record. Keep in mind, you've to make a document with .html extension.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form validation with Shake Effect | S-Tech04</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
</head>
<body>
<div class="wrapper">
<div class="logo"></div>
<div class="title">Login Form</div>
<form action="https://www.youtube.com/c/STech04" method="post">
<div class="field email">
<div class="input-area">
<input type="text" placeholder="Email Adderss">
<i class="icon fas fa-envelope"></i>
<i class="error error-icon fas fa-exclamation-circle"></i>
</div>
<div class="error error-txt">Email can't be blank</div>
</div>
<div class="field password">
<div class="input-area">
<input type="password" placeholder="Enter password">
<i class="icon fas fa-lock"></i>
<i class="error error-icon fas fa-exclamation-circle"></i>
</div>
<div class="error error-txt">Password can't be blank</div>
</div>
<input type="submit" value="Login">
</form>
<div class="link">
<a href="#">Forget password?</a> or <a href="#">sign up</a>
</div>
</div>
<script src="./script.js"></script>
</body>
</html>
Second, make a CSS record with the name of style.css and glue the given codes in your CSS document. Keep in mind, you've to make a record with .css extension.
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body
{
width: 1005;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #ecf0f3;
}
.wrapper
{
width: 380px;
padding: 40px 30px 50px 30px;
background: #ecf0f3;
box-shadow: 13px 13px 20px #cbced1,
-13px -13px 20px #ffffff;
border-radius: 40px;
}
.wrapper .logo
{
width: 100px;
height: 100px;
background: url(./logo.png);
background-size: cover;
border-radius: 50%;
box-shadow: 0 0 2px #5f5f5f,
0 0 0 5px #ecf0f3,
8px 8px 15px #a7aaaf;
margin: 0 auto;
}
.wrapper .title
{
padding-top: 24px;
font-size: 24px;
letter-spacing: 0.5px;
text-align: center;
}
.wrapper form
{
margin: 20px 0;
margin-bottom: 0;
}
.wrapper form .field
{
width: 100%;
margin-bottom: 30px;
}
form .field.shake
{
animation: shake 0.3s ease-in-out;
}
@keyframes shake
{
0%, 100%
{
margin-left: 0px;
}
20%, 80%
{
margin-left: -12px;
}
40%, 60%
{
margin-left: 12px;
}
}
.field .input-area
{
height: 50px;
width: 100%;
position: relative;
border-radius: 25px;
box-shadow: inset 8px 8px 8px #cbced1,
inset -8px -8px 8px #fff;
}
.field .input-area input
{
width: 100%;
height: 100%;
background: none;
border-radius: 5px;
border: none;
outline: none;
caret-color: #24cfaa;
padding: 0px 40px;
font-size: 18px;
}
.input-area i
{
position: absolute;
top: 50%;
pointer-events: none;
font-size: 18px;
transform: translateY(-50%);
}
.input-area i.icon
{
left: 15px;
color: #bfbfbf;
transition: color 0.2s ease;
}
.input-area .error-icon
{
right: 15px;
color: #dc3545;
}
.input-area input:focus ~ .icon,
form .field.valid .icon
{
color: #24cfaa;
}
form .field.shake input:focus ~ .icon,
form .field.error input:focus ~ .icon
{
color: #bfbfbf;
}
input::placeholder
{
color: #bfbfbf;
font-size: 17px;
}
.field .error-txt
{
color: #dc3545;
margin-top: 5px;
margin-left: 15px;
}
form .field .error
{
display: none;
}
form .field.shake .error,
form .field.error .error
{
display: block;
}
form input[type="submit"]
{
width: 100%;
height: 60px;
text-align: center;
color: #fff;
background: #24cfaa;
border-radius: 30px;
outline: none;
border: none;
font-size: 20px;
cursor: pointer;
box-shadow: 3px 3px 8px #d1d1d1,
-3px -3px 8px #ffffff;
}
form input[type="submit"]:hover
{
background: #18bb98;
}
.wrapper .link
{
padding-top: 20px;
text-align: center;
}
.link a
{
text-decoration: none;
color: #949393;
font-size: 15px;
}
.link a:hover
{
text-decoration: underline;
}
Last, create a JavaScript file with the name of script.js and paste the given codes in your JavaScript file. Remember, you’ve to create a file with .js extension.
const form = document.querySelector('form');
eField = form.querySelector('.email'),
eInput = eField.querySelector('input'),
pField = form.querySelector('.password'),
pInput = pField.querySelector('input');
form.onsubmit = (e)=>{
e.preventDefault();
(eInput.value == "") ? eField.classList.add("shake", "error") : checkEmail();
(pInput.value == "") ? pField.classList.add("shake", "error") : checkPassword();
setTimeout(() => {
eField.classList.remove('shake');
pField.classList.remove('shake');
}, 500);
eInput.onkeyup = ()=>{checkEmail();}
pInput.onkeyup = ()=>{checkPassword();}
function checkEmail(){
let pattern = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/; //pattern for validate email
if(!eInput.value.match(pattern)){
eField.classList.add("error");
eField.classList.remove("valid");
let errorTxt = eField.querySelector('.error-txt');
(eInput.value != "") ? errorTxt.innerText = "Enter a valid email address" : errorTxt.innerText = "Email can't be blank"
}else{
eField.classList.remove("error");
eField.classList.add("valid");
}
}
function checkPassword(){
if(pInput.value == ""){
pField.classList.add('error');
pField.classList.remove('valid');
}else{
pField.classList.remove('error');
pField.classList.add('valid');
}
}
if(!eField.classList.contains('error') && !pField.classList.contains('error')){
window.location.href = form.getAttribute('action') //redirecting user to the specified url which is inside action attribute of form tag
}
}
That’s all, now you’ve successfully created a program to How to create Login Form validation with Shake Effect. If your code doesn’t work or you’ve faced any error/problem, please download the source code files from the given download button. It’s free and a .zip file will be downloaded then you’ve to extract it.
Click on the following download button to download all source code files.
Post a Comment
How can I help you