-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDemo.js
55 lines (51 loc) · 1.65 KB
/
Demo.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
52
53
54
55
function validateName() {
var name = document.myform1.name.value;
if (name == null || name == '') {
document.getElementById("nameValidationMessage").innerText = "Name can't be blank";
} else {
document.getElementById("nameValidationMessage").innerText = "";
}
}
function validateEmail() {
var email = document.myform1.email.value;
var atposition = email.indexOf('@');
var dotposition = email.lastIndexOf('.');
if (
atposition < 1 ||
dotposition < atposition + 2 ||
dotposition + 2 >= email.length
) {
document.getElementById("emailValidationMessage").innerText = "Please enter a valid e-mail address";
} else {
document.getElementById("emailValidationMessage").innerText = "";
}
}
function validatePhone() {
var phoneInput = document.myform1.phone.value;
if (isNaN(phoneInput) || phoneInput.length != 10) {
document.getElementById("phoneValidationMessage").innerText = "Not a valid number";
} else {
document.getElementById("phoneValidationMessage").innerText = "";
}
}
function searchTable() {
var input, filter, found, table, tr, td, i, j;
input = document.getElementById('myInput');
filter = input.value.toUpperCase();
table = document.getElementById('myTable');
tr = table.getElementsByTagName('tr');
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName('td');
for (j = 0; j < td.length; j++) {
if (td[j].innerHTML.toUpperCase().indexOf(filter) > -1) {
found = true;
}
}
if (found) {
tr[i].style.display = '';
found = false;
} else {
tr[i].style.display = 'none';
}
}
}