Skip to content

Commit

Permalink
issue OpenClassrooms-Student-Center#2 validation for each input
Browse files Browse the repository at this point in the history
  • Loading branch information
k-mazats committed Feb 3, 2021
1 parent 18d23c5 commit b6fbb1e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
43 changes: 43 additions & 0 deletions starterOnly/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function firstValidation() {
let inputValue = document.getElementById("first").value;
if (inputValue !== null && inputValue.length > 2) return true;
else return false;
}

function lastValidation() {
let inputValue = document.getElementById("last").value;
if (inputValue !== null && inputValue.length > 2) return true;
else return false;
}

function emailValidation() {
let regex = /^([a-z0-9_\.-]+\@[\da-z\.-]+\.[a-z\.]{2,6})$/;
let inputValue = document.getElementById("email").value;
return regex.test(inputValue);
}

function quantityValidation() {
let regex = /^[0-9]+$/;
let inputValue = document.getElementById("quantity").value;
return regex.test(inputValue);
}

function locationValidation() {
let radioButtons = document.querySelectorAll(".checkbox-input[type=radio]");
for(let radio of radioButtons){
if(radio.checked === true) return true;
}
return false;
}

function checkboxValidation() {
let inputValue = document.getElementById("checkbox1").checked;
return inputValue;
}

document
.getElementById("button")
.addEventListener("click", function formValidation(event) {
event.preventDefault();
console.log(checkboxValidation());
});
4 changes: 2 additions & 2 deletions starterOnly/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ <h1 class="hero-headline">
type="checkbox"
name="checkbox1"
id="checkbox1"
checked

/>
<label class="checkbox2-label" for="checkbox1" required>
<span class="checkbox-icon"></span>
Expand All @@ -203,7 +203,7 @@ <h1 class="hero-headline">
<input
class="btn-submit"
type="submit"
class="button"
id="button"
value="C'est parti"
/>
</form>
Expand Down
26 changes: 26 additions & 0 deletions starterOnly/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ const modalBtn = document.querySelectorAll(".modal-btn");
const modalClose = document.querySelector(".close");
const formData = document.querySelectorAll(".formData");

// form validation functions

function firstValidation() {
let inputValue = document.getElementById("first").value;
if (inputValue !== null && inputValue.length < 2) return true;
else return false;
}

function lastValidation() {
let inputValue = document.getElementById("last").value;
}

function emailValidation() {
let inputValue = document.getElementById("email").value;
}

function quantityValidation() {
let inputValue = document.getElementById("quantity").value;
}
function locationValidation() {}

function checkboxValidation() {
let inputValue = document.getElementById("checkbox1").value;
}

// launch modal event
modalBtn.forEach((btn) => btn.addEventListener("click", launchModal));
Expand All @@ -31,3 +55,5 @@ function closeModal() {
}




0 comments on commit b6fbb1e

Please sign in to comment.