-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.js
More file actions
51 lines (34 loc) · 1.07 KB
/
Copy pathvalidation.js
File metadata and controls
51 lines (34 loc) · 1.07 KB
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 validateName() {
var nameInput = document.getElementById("name");
var name = nameInput.value;
if (!name.match(/^[a-zA-Z]+$/)) {
nameInput.classList.add("is-invalid");
alert("Nama harus terdiri dari huruf saja.");
return false;
} else {
nameInput.classList.remove("is-invalid");
return true;
}
}
function validateEmail() {
var emailInput = document.getElementById("email");
var email = emailInput.value;
if (!email.match(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/)) {
emailInput.classList.add("is-invalid");
alert("Email tidak valid.");
return false;
} else {
emailInput.classList.remove("is-invalid");
return true;
}
}
function validateForm() {
if (!validateName()) {
return false;
}
if (!validateEmail()) {
return false;
}
return true;
}
document.getElementById("submit").addEventListener("click", validateForm);