diff --git a/index.js b/index.js new file mode 100644 index 0000000..db65d4e --- /dev/null +++ b/index.js @@ -0,0 +1,23 @@ +let submitButton = document.querySelector('input[type="submit"]'); + +let telPhone = document.querySelector('input[type="tel"]'); +let email = document.querySelector('input[type="email"]'); + +let form = document.querySelector('form'); + +function validateEmail() { + return email.value.includes('@'); +} + +function validatePhone() { + const regex = /\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}/; + return telPhone.value.match(regex); +} + +form.addEventListener("submit", (e) => { + let isValidEmail = validateEmail() && validatePhone(); + if(!isValidEmail) { + alert("Данные не валидны"); + e.preventDefault(); + } +}); diff --git a/static/index.html b/static/index.html index 514b62f..b9d127e 100644 --- a/static/index.html +++ b/static/index.html @@ -8,9 +8,76 @@