Beautiful Subscribe Form With JavaScript Validation

Hi guys today i am writing about subscribe form, 90% of websites using subscribe form this feature use for user get weekly or monthly updated with latest post or whats new.
You have visit most of websites out of that some websites show you popup ans some give you option enter your email get weekly update and subscribe our newsletter.

So today i am sowing you a very simple beautiful subscribe form using htm, css, bootstrap with javascript validations. This subscribe form you can use any where and with any kind of website such as news, tutorial, product base, e-commerce, organization, property etc.

HTML Code of Subscribe Form

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Beautiful subscribe form</title>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css”>
</head>

<body>
<section id=”subscriber_sec”>
<div class=”container”>
<div class=”col-lg-12 section-title”>
<h2>Subscribe Our Newsletter</h2>
</div>
<form method=”post” name=”subscribenewsletter” onsubmit=”return subscribeValidations();”>
<div class=”col-md-5″>
<input type=”text” class=”form-control” name=”subscriber_name” id=”subscriber_name” placeholder=”Your Name” />
</div>
<div class=”col-md-5″>
<input type=”text” class=”form-control” name=”subscriber_email” id=”subscriber_email” placeholder=”Your Email” />
</div>
<div class=”col-md-2″>
<input type=”submit” class=”form-control” name=”subscribenewsletter” value=”Subscribe” />
</div>
</form>
</div>
</section>
</body>
</html>


CSSCode of Subscribe Form

<style>
#subscriber_sec{
background: #304352;
color: #ffffff;
padding:50px 0px;
}

#subscriber_sec .form-control {
background: transparent;
box-shadow: none;
border: 1px solid #f9f9f9;
color: #ccc;
font-size: 20px;
margin-top: 10px;
margin-bottom: 14px;
transition: all 0.4s ease-in-out;
}

#subscriber_sec .form-control:focus {
border-color: #e44c65;
color: #ffffff;
}

#subscriber_sec input {
height: 55px;
}

#subscriber_sec input[type=”submit”] {
background: #e44c65;
border:none;
color: #ffffff;
font-weight: 400;
letter-spacing: 1px;
}

#subscriber_sec input[type=”submit”]:hover {
background: #222;
color: #ffffff;
}
</style>


JavaScript Code of Subscribe Form

<script>
function subscribeValidations()
{
 var emailReg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
 
 var subscriber_name = document.getElementById("subscriber_name").value;
 var subscriber_email = document.getElementById("subscriber_email").value;
 subscriber_name = subscriber_name.trim();
 subscriber_email = subscriber_email.trim();
 
 if(subscriber_name=="" || subscriber_name==" ")
 {
 document.subscribenewsletter.subscriber_name.focus();
 document.getElementById("subscriber_name").style.borderColor="#CE0505";
 alert("Enter Your Name!");
 return false;
 }
 if(subscriber_email=="")
 {
 document.subscribenewsletter.subscriber_email.focus();
 document.getElementById("subscriber_name").style.borderColor="rgb(15, 171, 15)";
 document.getElementById("subscriber_email").style.borderColor="#CE0505";
 alert("Enter Your Email!");
 return false;
 }
 
 if (emailReg.test(subscriber_email) == false) 
 {
 document.subscribenewsletter.subscriber_email.focus();
 document.getElementById("subscriber_name").style.borderColor="rgb(15, 171, 15)";
 document.getElementById("subscriber_email").style.borderColor="#CE0505";
 alert("Enter Valid Email!");
 return false;
 }
}
</script>

Leave a Reply

Related Posts: You may like

Responsive Coming Soon Template

Stylish responsive sidebar menu navigation

Social sharing button sidebar widget

Pure css dropdown navigation bar

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.