Skip to content

Commit

Permalink
Merge pull request #1 from student-aditipaliwal/student-aditipaliwal-…
Browse files Browse the repository at this point in the history
…patch-1

Form Validation issue jaysomani#116
  • Loading branch information
student-aditipaliwal authored Feb 5, 2024
2 parents 65dcca7 + 6503cac commit 43c0663
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pages/contact/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>Contact us</h1>
</div>
<div class="side">
<p>
<input id="nameInput" type="text" placeholder="Your name">
<input id="nameInput" type="text" placeholder="Your name" oninput="validateName('nameInput')">
</p>
<p>
<input id="emailInput" type="email" placeholder="Your email">
Expand All @@ -41,6 +41,24 @@ <h1>Contact us</h1>

<script src="./contact.js"></script>

<!-- ADDING FORM VALIDATION IN NAME FIELD -->


<script>


function validateName(inputId) {
let input = document.getElementById(inputId);
let value = input.value;
let regex = /^[A-Za-z ]+$/;

if (!regex.test(value)) {
alert("Please enter only characters in the name field.");
input.value = value.replace(/[^A-Za-z ]/g, ''); // Remove any non-alphabetic characters
}
}

</script>
</body>

</html>
</html>

0 comments on commit 43c0663

Please sign in to comment.