JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head></head>
<body>
<form method="post" action="#" id="frm_subscribe">
<input type="email" name="email" value="emailnotvalid" />
<input type="submit" value="SUBSCRIBE" />
<div class="error"></div>
</form>
</body>
</html>
CSS
body{font-size: 12px;}
#frm_subscribe {
position: relative;
width: 400px;
heigth: 200px;
margin: 40px auto;
}
#frm_subscribe input[type='email'] {
width: 200px;
padding: 5px;
border: 2px solid #2276E3 ;
border-radius: 4px;
box-shadow: 0 1px 3px #b7deed;
}
#frm_subscribe input[type='submit'] {
background: #b7deed; /* Old browsers */
background: -moz-linear-gradient(top, #b7deed 0%, #71ceef 50%, #21b4e2 51%, #b7deed 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b7deed), color-stop(50%,#71ceef), color-stop(51%,#21b4e2), color-stop(100%,#b7deed)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #b7deed 0%,#71ceef 50%,#21b4e2 51%,#b7deed 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #b7deed 0%,#71ceef 50%,#21b4e2 51%,#b7deed 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #b7deed 0%,#71ceef 50%,#21b4e2 51%,#b7deed 100%); /* IE10+ */
background: linear-gradient(to bottom, #b7deed 0%,#71ceef 50%,#21b4e2 51%,#b7deed 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b7deed', endColorstr='#b7deed',GradientType=0 ); /* IE6-9 */
padding: 5px;
border: 2px solid #b7deed;
border-radius: 4px;
color: #666;
}
.error{
display: none;
color: red;
font-family: Arial;
}
JavaScript
$('input[type="submit"]').click(function(e){
var email = $("input[type='email']");
if(IsEmail($("input[type='email']").val())){
$('.error').hide();
}else{
//not valid
$('.error').show().html('Please enter a valid email');
}
});
function IsEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}