<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/style.css">
<title>Form Validation</title>
<style>
*
{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body
{
width: 100%;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-image: linear-gradient(rgb(0 0 0 / 6%) ,#ffeb3b21),url(https://i.picsum.photos/id/838/1920/1200.jpg?blur=2&hmac=X30K7DUryf_MjrjCxLuXNOvDNiBSRy6hUU4flx7BoOQ);
background-size: cover;
background-position: center;
}
form {
padding: 100px;
background: rgba( 255, 255, 255, 0.15 );
box-shadow: 0 8px 32px 0 rgba( 31, 38, 135, 0.37 );
backdrop-filter: blur( 12.0px );
-webkit-backdrop-filter: blur( 12.0px );
border-radius: 10px;
}
form input {
background-color: rgba(255, 255, 255, 0.85) !important;
}
@media only screen and (max-width: 768.98px) {
form {
padding: 30px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<form action="#" class="rounded w-100" onsubmit="return formvalid()">
<div class="form-group input-group-sm">
<label class="text-white font-weight-normal" for="name">Name</label>
<input type="text" class="form-control" id="name">
<small id="nameHelp" class="form-text text-light"></small>
</div>
<div class="form-group input-group-sm">
<label class="text-white font-weight-normal" for="email">Email address</label>
<input type="email" class="form-control" id="email">
<small id="emailHelp" class="form-text text-light"></small>
</div>
<div class="form-group input-group-sm">
<label class="text-white font-weight-normal" for="phone">Phone Number</label>
<input type="text" class="form-control" id="phone">
<small id="phoneHelp" class="form-text text-light"></small>
</div>
<div class="form-group input-group-sm">
<label class="text-white font-weight-normal" for="pass">Password</label>
<input type="password" class="form-control" id="pass">
<small id="passHelp" class="form-text text-light"></small>
</div>
<div class="form-group input-group-sm">
<label class="text-white font-weight-normal" for="conpass">Confirm Password</label>
<input type="password" class="form-control" id="conpass">
<small id="conpassHelp" class="form-text text-light"></small>
</div>
<button type="submit" class="btn text-white bg-danger btn-lg btn-block mt-5">Submit</button>
</form>
</div>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 2: jQuery, Popper.js, and Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
<script>
function formvalid(){
var nameVal = document.getElementById("name").value;
var emailVal = document.getElementById("email").value;
var phoneVal = document.getElementById("phone").value;
var passVal = document.getElementById("pass").value;
var conpassVal = document.getElementById("conpass").value;
if (nameVal == "") {
document.getElementById("nameHelp").innerHTML = "Please Enter your Name";
return false;
}
if ((nameVal.length <= 2 ) || (nameVal.length >= 20 )){
document.getElementById("nameHelp").innerHTML = "Your Name must be 2 to 20 Character.";
return false;
}
if (!isNaN(nameVal)) {
document.getElementById("nameHelp").innerHTML = "Please Enter a valid Name.";
return false;
}
if (emailVal == "") {
document.getElementById("emailHelp").innerHTML = "Please Enter your email";
document.getElementById("nameHelp").innerHTML = " ";
return false;
}
if (emailVal.indexOf('@') <= 0) {
document.getElementById("emailHelp").innerHTML = "Invalid @ position";
document.getElementById("nameHelp").innerHTML = " ";
return false;
}
if ((emailVal.charAt(emailVal.length - 4) != '.') && (emailVal.charAt(emailVal.length - 3) != '.')){
document.getElementById("emailHelp").innerHTML = "Invalid ' . ' position";
document.getElementById("nameHelp").innerHTML = " ";
return false;
}
if (/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/.test(emailVal) == false) {
$('#emailHelp').text('Please Enter a valid Email Address.');
document.getElementById("nameHelp").innerHTML = " ";
return false;
}
if (phoneVal == "") {
document.getElementById("phoneHelp").innerHTML = "Please Enter your phone";
document.getElementById("emailHelp").innerHTML = " ";
return false;
}
if (isNaN(phoneVal)) {
document.getElementById("phoneHelp").innerHTML = "Please Enter only Digits";
document.getElementById("emailHelp").innerHTML = " ";
return false;
}
if ((phoneVal.length != 10 ) && (phoneVal.length != 11 ) && (phoneVal.length != 12 )){
document.getElementById("phoneHelp").innerHTML = "Your Phone must be 10 to 12 Digits.";
document.getElementById("emailHelp").innerHTML = " ";
return false;
}
if (/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/.test(phoneVal) == false) {
document.getElementById("phoneHelp").innerHTML = "Please enter a valid phone Number.";
document.getElementById("emailHelp").innerHTML = " ";
}
if (passVal == "") {
document.getElementById("passHelp").innerHTML = "Please Enter your Password";
document.getElementById("phoneHelp").innerHTML = " ";
return false;
}
if ((passVal.length <= 2 ) || (passVal.length >= 20 )){
document.getElementById("passHelp").innerHTML = "Your Password must be 2 to 20 Character.";
document.getElementById("phoneHelp").innerHTML = " ";
return false;
}
if (passVal != conpassVal) {
document.getElementById("conpassHelp").innerHTML = "Password are not Matching";
document.getElementById("phoneHelp").innerHTML = " ";
document.getElementById("passHelp").innerHTML = " ";
return false;
}
if (conpassVal == "") {
document.getElementById("conpassHelp").innerHTML = "Please Enter your Confirm Password";
document.getElementById("passHelp").innerHTML = " ";
return false;
}
return true;
}
/*validate with REGEX 101*/
var usercheck = /^[A-Za-z. ]{3,30}$/; /*{min, max}*/
var passwordcheck = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,16}$/; /*(? = .* means one required from given along with )*/
var email = /^[A-Za-z_.]{3,}@[A-Za-z]{3,}[.]{1}[A-Za-z.]{2,6}$/;
var mobile = /^[789][0-9]{9}$/; /*[789]means one compulsory digit take from this*/
/*test using REGEX*/
if (usercheck.test(nameVal)){
/*statement*/
}
</script>
</body>
</html>
$('#blanket-submit').on("click" , function (){
var email = $('#email').val();
var name = $('#name').val();
var phone = $('#phone').val();
if($('#name').val() =="" || $('#email').val()=="" || $('#phone').val() == "" || $('#address').val() == "" ){
$('#errtxt').text('All fields are mandatory!');
}
else if (!isNaN(name)) {
$('#errtxt').text('Please Enter a valid Name.');
}
else if ((name.length < 2) || (name.length > 20)) {
$('#errtxt').text('Your Name must be 2 to 20 Character.');
}
else if (/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/.test(email) == false) {
$('#errtxt').text('Please enter a valid Email Address.');
}
else if (/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/.test(phone) == false) {
$('#errtxt').text('Please enter a valid Contact Number.');
}
else{