contact information form validation

This commit is contained in:
soyed 2021-03-10 19:52:08 -05:00
parent 825e43a581
commit 00c5fa9b18
3 changed files with 153 additions and 50 deletions

View file

@ -271,6 +271,13 @@ input:valid+span:after {
padding-left: 5px; padding-left: 5px;
} }
.errorMsg {
color: red;
}
.accountLabel {
text-align: left;
}
/* Footer section */ /* Footer section */

View file

@ -296,7 +296,7 @@
<h2 class="big-heading"> <i class="far fa-clock"></i> Book an Appointment </h2> <h2 class="big-heading"> <i class="far fa-clock"></i> Book an Appointment </h2>
<br> <br>
<!-- Accordion for booking a service--> <!-- Accordion for booking a service-->
<form onsubmit="validateForm()" method="post"> <form method="post" id="contactForm">
<div id="accordion"> <div id="accordion">
<!-- Service Accordion --> <!-- Service Accordion -->
@ -321,6 +321,7 @@
<option value="3">Full Repair/Maintenance</option> <option value="3">Full Repair/Maintenance</option>
<option value="3">Other Inquiries</option> <option value="3">Other Inquiries</option>
</select> </select>
<span id="serviceError" class="errorMsg"></span>
<hr> <hr>
<h2><i class="fas fa-users"></i> Mechanics</h2> <h2><i class="fas fa-users"></i> Mechanics</h2>
<p>Please select your technican</p> <p>Please select your technican</p>
@ -332,6 +333,7 @@
<option value="3">Stewart</option> <option value="3">Stewart</option>
<option value="4">No preference</option> <option value="4">No preference</option>
</select> </select>
<p id="technicanError" class="errorMsg"></p>
<hr> <hr>
<!-- notify user of the availability of technican before selecting time, let them block dates that arent bookable and let users know--> <!-- notify user of the availability of technican before selecting time, let them block dates that arent bookable and let users know-->
<h2><i class="fas fa-calendar-plus"></i> Appointment Time</h2> <h2><i class="fas fa-calendar-plus"></i> Appointment Time</h2>
@ -340,10 +342,12 @@
<div class="request-label"> <div class="request-label">
<label for="appTime">Choose an appointment date: </label> <label for="appTime">Choose an appointment date: </label>
<input type="text" id="datepicker"> <input type="text" id="datepicker">
<p id="dateError" class="errorMsg"></p>
<div> <div>
<label for="appt-time">Choose an appointment time (8:30am - 10:00pm): </label> <label for="appt-time">Choose an appointment time (8:30am - 10:00pm): </label>
<input id="appt-time" type="time" name="appt-time" min="12:00" max="18:00"> <input id="appt-time" type="time" name="appt-time" min="12:00" max="18:00">
<span class="validity"></span> <span class="validity"></span>
<p id="timeError" class="errorMsg"></p>
</div> </div>
</div> </div>
</div> </div>
@ -366,25 +370,29 @@
<!-- <form> --> <!-- <form> -->
<div class="form-group"> <div class="form-group">
<div class="row"> <div class="row">
<div class="col-6" style="float: right;"> <div class="col-6 accountLabel" style="float: right;">
<label for="fnameLabel">First Name</label> <label for="fnameLabel">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="First Name"> <input type="text" id="fname" name="firstname" placeholder="First Name">
<p id="fnameError" class="errorMsg"></p>
</div> </div>
<div class="col-6"> <div class="col-6 accountLabel">
<label for="lnameLabel">Last Name</label> <label for="lnameLabel">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Last Name"> <input type="text" id="lname" name="lastname" placeholder="Last Name">
<p id="lnameError" class="errorMsg"></p>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="row"> <div class="row">
<div class="col-6" style="float: right;"> <div class="col-6 accountLabel" style="float: right;">
<label for="phoneNumLabel">Phone Number</label> <label for="phoneNumLabel">Phone Number</label>
<input type="text" id="phoneNum" name="phoneNumber" placeholder="Phone Number"> <input type="text" id="phoneNum" name="phoneNumber" placeholder="Phone Number">
<p id="phoneNumberError" class="errorMsg"></p>
</div> </div>
<div class="col-6"> <div class="col-6 accountLabel">
<label for="emailLabel">Email</label> <label for="emailLabel">Email</label>
<input type="text" id="email" name="email" placeholder="Email"> <input type="text" id="email" name="email" placeholder="Email">
<p id="emailError" class="errorMsg"></p>
</div> </div>
</div> </div>
</div> </div>
@ -393,25 +401,29 @@
<p>Please fill the spaces below with your payment information</p> <p>Please fill the spaces below with your payment information</p>
<div class="form-group"> <div class="form-group">
<div class="row"> <div class="row">
<div class="col-6" style="float: right;"> <div class="col-6 accountLabel" style="float: right;">
<label for="cardHolderLabel">Name on the card</label> <label for="cardHolderLabel">Name on the card</label>
<input type="text" id="cardHolder" name="cardHolder" placeholder="Name on the Card"> <input type="text" id="cardHolder" name="cardHolder" placeholder="Name on the Card">
<p id="cardHolderError" class="errorMsg"></p>
</div> </div>
<div class="col-6"> <div class="col-6 accountLabel">
<label for="creditCardLabel">Credit Card</label> <label for="creditCardLabel">Credit Card</label>
<input type="text" id="creditCard" name="creditCard" placeholder="Credit Card"> <input type="text" id="creditCard" name="creditCard" placeholder="Credit Card">
<p id="creditCardError" class="errorMsg"></p>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="row"> <div class="row">
<div class="col-4"> <div class="col-4 accountLabel">
<label for="expiryDateLabel">Expiry Date</label> <label for="expiryDateLabel">Expiry Date</label>
<input type="text" id="expiryDate" name="expiryDate" placeholder="Expiry Date"> <input type="text" id="expiryDate" name="expiryDate" placeholder="Expiry Date">
<p id="expiryDateError" class="errorMsg"></p>
</div> </div>
<div class="col-2"> <div class="col-2 accountLabel">
<label for="cvvLabel">CVV</label> <label for="cvvLabel">CVV</label>
<input type="text" id="expiryDate" name="cvv" placeholder="CVV"> <input type="text" id="cvv" name="cvv" placeholder="CVV">
<p id="cvvError" class="errorMsg"></p>
</div> </div>
</div> </div>
</div> </div>
@ -423,7 +435,7 @@
<br> <br>
<br> <br>
<!--<input type="submit" value="Submit"> --> <!--<input type="submit" value="Submit"> -->
<button type="button" class="btn btn-lg btn-outline-secondary alert" id="submitButton"">Submit</button> <button type="button" class="btn btn-lg btn-outline-secondary" id="submitButton" onclick="validateForm()">Submit</button>
</form> </form>
</div> </div>
</section> </section>

View file

@ -1,55 +1,139 @@
// Calendar Validation
function toAppointment() { function toAppointment() {
document.getElementById('appointment').scrollIntoView(); document.getElementById('appointment').scrollIntoView();
} }
// Calendar Validation
// //logic was gotten from
// https://forum.jquery.com/topic/disable-single-day-of-a-week-in-datepicker
var value = 0; var value = 0;
$(function() { $(function() {
$("#datepicker").datepicker({ $("#datepicker").datepicker({
beforeShowDay: getAvailability beforeShowDay: getAvailability
}); });
}); });
function getMechanic(selectObject) { function getMechanic(selectObject) {
value = selectObject.value; value = selectObject.value;
} }
function getAvailability(date) { function getAvailability(date) {
if (value == 1 && (date.getDay() === 0 || date.getDay() == 6)) /* restrict weekends */ if (value == 1 && (date.getDay() === 0 || date.getDay() == 6)) /* restrict weekends */
return [false] return [false]
if (value == 2 && (date.getDay() === 0 || date.getDay() == 1 || date.getDay() == 4 || date.getDay() == 5 || date.getDay() == 6)) /* restrict M,Thurs, Fri, Sat, Sun */ if (value == 2 && (date.getDay() === 0 || date.getDay() == 1 || date.getDay() == 4 || date.getDay() == 5 || date.getDay() == 6)) /* restrict M,Thurs, Fri, Sat, Sun */
return [false] return [false]
if (value == 3 && (date.getDay() === 0 || date.getDay() == 4 || date.getDay() == 5 || date.getDay() == 6)) /* restrict Thurs, Fri, Sat, Sun */ if (value == 3 && (date.getDay() === 0 || date.getDay() == 4 || date.getDay() == 5 || date.getDay() == 6)) /* restrict Thurs, Fri, Sat, Sun */
return [false] return [false]
if (date.getDay() === 0 || date.getDay() == 6) /* weekends */ if (date.getDay() === 0 || date.getDay() == 6) /* weekends */
return [false] return [false]
else else
return [true, "", ""] return [true, "", ""]
} }
//grab my Form
var form = $('#contactForm');
//Form Validation //Form Validation
function validateForm(){ function validateForm() {
//first check that the user has selected, //first check that the user has selected,
var serviceSelected = $('#selectService option:selected').val(); var serviceSelected = $('#selectService option:selected').val();
console.log(optionSelected); if (serviceSelected === "Select Service") {
if (serviceSelected === "Select Service"){ $('#serviceError').html("*Please select a service");
alert("*Please select a service"); } else {
} $('#serviceError').html("");
}
//next check for the technician selected by the users //next check for the technician selected by the users
var technicanSelected = $('#technicanSelected option:selected').val(); if ($('#selectTechnican option:selected').val() === "Select technican") {
console.log(technicanSelected); $('#technicanError').html("*Please select a technican");
if(technicanSelected === "Select technican"){ } else {
alert("*Please select a technican") $('#technicanError').html("");
} }
//next, check for appointment date selection //next, check for appointment date selection
//next, check for appointment time selection if ($('#datepicker').val() === "") {
$('#dateError').html("*Please select an appointment Date");
} else {
$('#dateError').html("");
}
//next, check for appointment time selection
var timeSelected = $('#appt-time').val();
if ($('#appt-time').val() === "") {
$('#timeError').html("*Please select an appointment time");
} else {
$('#timeError').html("");
}
// Account Section
// //check the first Name Field
if ($('#fname').val() === "" || !$('#fname').val().length) {
$("#fnameError").html("*Please enter your first name");
} else {
$("#fnameError").html("");
}
//check the last name field
if ($('#lname').val() === "" || !$('#lname').val().length) {
$("#lnameError").html("*Please enter your last name");
} else {
$("#lnameError").html("");
}
//check the phone number Field and validate phone number
// var phoneNumber = $('#phoneNum').val();
//this filter was gotten from this website to valid the phone Number *https://www.w3resource.com/javascript/form/phone-no-validation.php*
var phoneFilter = /^\d{10}$/;
// console.log(phoneNumber);
if ($('#phoneNum').val() === "" || !$('#phoneNum').val().length) {
$("#phoneNumberError").html("*Please enter your Phone Number");
} else if (!$('#phoneNum').val().match(phoneFilter)) {
$("#phoneNumberError").html("*Invalid phone number please enter a 10 digit number");
} else {
$("#phoneNumberError").html("");
}
//source of this is from the link below
//https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
var emailFilter = /^\S+@\S+$/;
if ($('#email').val() === "" || !$('#email').val().length) {
$("#emailError").html("*Please enter your email Address");
} else if (!$('#email').val().match(emailFilter)) {
$("#emailError").html("*Please enter a valid email address");
} else {
$("#emailError").html("");
}
// Account Section
//check for creditCard holder name // console.log(cardHolder);
// check for credit card Format. if ($('#cardHolder').val() === "" || !$('#cardHolder').val().length) {
// check for t $("#cardHolderError").html("*Please enter name on the card");
} else {
$("#cardHolderError").html("");
}
//the logic used for the filters in this section was gotten from
////https://stackoverflow.com/questions/6176802/how-to-validate-a-credit-card-number
var creditFilter = /^\d{16}$/;
if ($('#creditCard').val() === "" || !$('#creditCard').val().length) {
$("#creditCardError").html("*Please enter your valid credit card number");
} else if (!$('#creditCard').val().match(creditFilter)) {
$("#creditCardError").html("*Invalid credit card number. Please enter a valid 16 digit credit card");
} else {
$("#creditCardError").html("");
}
var expiryFilter = /^\d{4}$/;
if ($('#expiryDate').val() === "" || !$('#expiryDate').val().length) {
$("#expiryDateError").html("*Please enter your credit card expiry date");
} else if (!$('#expiryDate').val().match(expiryFilter)) {
$("#expiryDateError").html("*Invalid expiry date. Please enter a valid expiry date of format MMYY!");
} else {
$("#expiryDateError").html("");
}
var cvvFilter = /^\d{3}$/;
if ($('#cvv').val() === "" || !$('#cvv').val().length) {
$("#cvvError").html("*Please enter your credit card CVV");
} else if (!$('#cvv').val().match(cvvFilter)) {
$("#cvvError").html("*Please enter 3 digit number");
} else {
$("#cvvError").html("");
}
} }