JSFiddle - React, Tailwind, and code Playground
HTML
<div class="form-input col">
<form action="index.php" method="post" id="contactform" name="contactform">
<label for="name">Name</label>
<input type="text" id="name" name="user_name" placeholder="E.g. John Smith">
<span id="errorname" class="error">Name is required</span>
<label for="email">Email</label>
<input type="email" id="email" name="user_email" placeholder="E.g. johnsmith@hotmail.com">
<span id="testy" class="error">Invalid Email</span>
<label for="message">Message</label>
<textarea id="message" name="user_message" placeholder="Hi! I wanted to suggest..." ></textarea>
<span id="errormessage" class="error">Message is required</span>
<button type="submit" id="submit" value="submit">Submit</button>
</form>
</div>
CSS
/* ============================
Base Element Styles
=============================== */
.clearfix:after
{
display: block;
clear: both;
content: '';
}
*
{
box-sizing: border-box;
}
a
{
text-decoration: none;
}
body
{
font-family: Segoe UI;
padding-top: 42px;
}
h1
{
font-size: 3em;
margin-top: 0;
text-align: center;
color: #000;
}
h2
{
font-size: 2em;
text-align: center;
}
img
{
max-width: 100%;
}
.container
{
padding-right: 1em;
padding-left: 1em;
}
footer
{
padding-top: 1em;
padding-bottom: 1em;
text-align: center;
background-color: #d3d3d3;
}
.btn
{
display: inline-block;
text-align: center;
}
.primary
{
text-align: center;
}
.center
{
text-align: center;
}
.btn
{
font-family: Arial;
font-size: 20px;
padding: 10px 20px 10px 20px;
text-decoration: none;
color: #fff;
-webkit-border-radius: 28;
-moz-border-radius: 28;
border-radius: 28px;
background: #3498db;
background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
background-image: -moz-linear-gradient(top, #3498db, #2980b9);
background-image: -ms-linear-gradient(top, #3498db, #2980b9);
background-image: -o-linear-gradient(top, #3498db, #2980b9);
background-image: linear-gradient(to bottom, #3498db, #2980b9);
}
.btn:hover
{
text-decoration: none;
background: #3cb0fd;
background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
}
/* ============================
Header
=============================== */
header
{
width: 100%;
padding: 200px 0;
background: /* top, transparent red, faked...
JavaScript
/*************************
CONTACT FORM VALIDATION
*/////////////////////////
// Check Length of Name and Message Fields
function checkLength() {
if($(this).val().length < 1) {
$(this).next().show();
} else {
$(this).next().hide();
}
}
// Check if email is valid
function validateEmail(email) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test(email);
}
$('#email').keyup(function() {
if(validateEmail($('#email').val())) {
$(this).next().hide();
} else {
$(this).next().show();
}
});
// Length Check Calls
$('#name').keyup(checkLength);
$('#message').keyup(checkLength);
// $('#email').keyup(checkLength);
function checkIfHidden() {
return $("#errorname").is(':hidden');
}
function enableSubmitEvent() {
if(checkIfHidden()) {
$('#submit').prop('disabled', false);
} else {
$('#submit').prop('disabled', true);
}
}
enableSubmitEvent();