-
Notifications
You must be signed in to change notification settings - Fork 0
/
rf1.js
51 lines (49 loc) · 1.81 KB
/
rf1.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
46
47
48
49
50
51
function validateForm() {
$( ".has-error" ).removeClass("has-error");
if (isEmpty(document.getElementById('data_2').value.trim())) {
alert('First name is required!');
document.getElementById('data_2').parentNode.className += " has-error";
return false;
}
if (isEmpty(document.getElementById('data_3').value.trim())) {
alert('Last name is required!');
document.getElementById('data_3').parentNode.className += " has-error";
return false;
}
if (isEmpty(document.getElementById('data_4').value.trim())) {
alert('Phone is required!');
document.getElementById('data_4').parentNode.className += " has-error";
return false;
}
if (isEmpty(document.getElementById('data_5').value.trim())) {
alert('Email is required!');
document.getElementById('data_5').parentNode.className += " has-error";
return false;
}
if (!validateEmail(document.getElementById('data_5').value.trim())) {
alert('Email must be a valid email address!');
document.getElementById('data_5').parentNode.className += " has-error";
return false;
}
if (isEmpty(document.getElementById('data_6').value.trim())) {
alert('Arrival date is required!');
document.getElementById('data_6').parentNode.className += " has-error";
return false;
}
if (isEmpty(document.getElementById('data_7').value.trim())) {
alert('Departure date is required!');
document.getElementById('data_7').parentNode.className += " has-error";
return false;
}
if (isEmpty(document.getElementById('data_8').value.trim())) {
alert('Number of adults is required!');
document.getElementById('data_8').parentNode.className += " has-error";
return false;
}
return true;
}
function isEmpty(str) { return (str.length === 0 || !str.trim()); }
function validateEmail(email) {
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,15}(?:\.[a-z]{2})?)$/i;
return isEmpty(email) || re.test(email);
}