-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (34 loc) · 1.27 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let sendButton = document.getElementById('send');
let cancelButton = document.getElementById('cancel');
let form = document.getElementById('form');
form.addEventListener('submit', function (e) {
e.preventDefault();
});
cancelButton.addEventListener('click', function () {
document.location.href = 'index.html';
});
sendButton.addEventListener('click', function (e) {
let name = document.getElementById('name');
let email = document.getElementById('email');
let message = document.getElementById('message');
name = name.value;
localStorage.setItem('name', name);
email = email.value;
localStorage.setItem('email', email);
message = message.value;
localStorage.setItem('message', message);
if(email === '' || name === '' || message === '') {
alert('All Feilds are required');
document.location.href = 'contact.html';
}
else if (!isemail(email)) {
alert('Please enter valid email address');
document.location.href = 'contact.html';
}
else {
document.location.href = 'index.html';
}
});
function isemail(email){
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email);
}