-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo14.html
More file actions
103 lines (103 loc) · 3.23 KB
/
Copy pathDemo14.html
File metadata and controls
103 lines (103 loc) · 3.23 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<style type="text/css">
.span_loi{
color: red;
}
</style>
</head>
<body>
<form>
Tên
<input type="text" id = "ten">
<span id="loi_ten" class="span_loi"></span>
<br>
Ngày sinh
<input type="date" id="ngay_sinh">
<span id="loi_ngay_sinh" class="span_loi"></span>
<br>
Giới tính
<input type="radio" name="gioi_tinh">Nam
<input type="radio" name="gioi_tinh">Nữ
<span id="loi_gioi_tinh" class="span_loi"></span>
<br>
Mật khẩu
<input type="password" id="mat_khau" name="">
<span id="loi_mat_khau" class="span_loi"></span>
<br>
Email
<input type="Email" id="Email">
<br>
Lớp
<select>
<option>Lập trình</option>
<option>Bảo mật</option>
<option>Dạy học</option>
</select>
<br>
<button type="button" onclick="return kiem_tra()">Đăng kí</button>
</form>
<script type="text/javascript">
function kiem_tra() {
let kiem_tra_loi = false;
//ten
let ten = document.getElementByid('ten').value;
if(ten.length === 0)
{
document.getElementByid('loi_ten').innerHTML = 'Tên không được để trống';
kiem_tra_loi = true;
} else {
let regex_ten = /^([A-ZÀÁÃẠẢĂẮẰẲẴẶÂẤẦẨẪẬÈÉẸẺẼÊỀẾỂỄỆĐÌÍĨỈỊÒÓÕỌỎÔỐỒỔỖỘƠỚỜỞỠỢÙÚŨỤỦƯỨỪỬỮỰỲỴỶỸÝ][a-zàáãạảăắằẳẵặâấầẩẫậèéẹẻẽêềếểễệđìíĩỉịòóõọỏôốồổỗộơớờởỡợùúũụủưứừửữựỳỵỷỹý]{1,6} ?)+$/;
//==false
if (!regex_ten.test(ten)) {
document.getElementByid('loi_ten').innerHTML = 'Tên không hợp lệ';
kiem_tra_loi = true;
} else {
document.getElementByid('loi_ten').innerHTML = '';
}
}
//ngay sinh
let ngay_sinh = document.getElementByid('ngay_sinh').value;
if(ngay_sinh.length === 0){
document.getElementByid('loi_ngay_sinh').innerHTML = 'Ngày sinh không được để trống';
kiem_tra_loi = true;
}else {
document.getElementByid('loi_ngay_sinh').innerHTML = '';
}
//gioi tinh
let mang_gioi_tinh = document.getElementsByName('gioi__tinh');
let kiem_tra_gioi_tinh = false;
for (let i = 0; i < mang_gioi_tinh.length; i++){
if (mang_gioi_tinh[i].checked) {
kiem_tra_gioi_tinh = true;
}
}
if (kiem_tra_gioi_tinh == false) {
document.getElementByid('loi_gioi_tinh').innerHTML = 'Giới tính không được để trống';
kiem_tra_loi = true;
} else {
document.getElementByid('loi_gioi_tinh').innerHTML = '';
}
//mat khau
let input_mat_khau =document.getElementByid('mat_khau');
let mat_khau = input_mat_khau.value;
if (mat_khau.length === 0) {
document.getElementByid('loi_mat_khau').innerHTML = 'Mật khẩu không được để trống';
kiem_tra_loi = true;
} else if(mat_khau.length < 8){
document.getElementByid('loi_mat_khau').innerHTML = 'Mật khẩu không được ngắn quá, dễ bị hack đấy đồ ngốc ạ.';
kiem_tra_loi = true;
} else{
document.getElementByid('loi_mat_khau').innerHTML = '';
}
if (kiem_tra_loi) {
return false;
}
}
</script>
</body>
</html>