-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab.html
61 lines (61 loc) · 2.71 KB
/
lab.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>lab 2</title>
<script type="text/javascript">
function checking(){
//Read the values of email, name, surname and postcode fields in the email, name, surname and postcode
var email=document.forms["form"]["email"].value;
var name=document.forms["form"]["name"].value;
var surname=document.forms["form"]["surname"].value;
var postcode=document.forms["form"]["postcode"].value;
//If the name field is empty or consist not only letters, show a message and prevent sending form
if (!name.value.match(/^[a-zA-z]+$/)){
document.getElementById("name-error").innerHTML='*please, enter the correct name';
}
//If the surname field is empty or consist not only letters, show a message and prevent sending form
if (!surname.value.match(/^[a-zA-Z]+$/)){
document.getElementById("surname-error").innerHTML='*please, enter the correct surname';
}
//If the postcode field doesn't contain only 5 numbers, show a message and prevent sending form
if (!postcode.value.match(/^\d{5}$/)){
document.getElementById("postcode-error").innerHTML='*the postcode must contain 5 numbers';
}
//If the email field is empty, show a message and prevent sending form
if (email.length==0) {
document.getElementById("email-error").innerHTML = '*the field is required';
}
//Check if the value of email field
//If the field doesn't contain this symbol, then the email value was entered incorrectly
if (!email.value.match(/^(?!.*\.{2})(?!.*\-{2})(?!.*_{2})[a-zA-Z0-9]+[a-zA-Z0-9_\|.|\-]*[a-zA-Z0-9]+@[a-zA-Z]+\.[a-zA-Z]+$/)){
document.getElementById("email-error").innerHTML='*please, enter correct email';
}
return true;
}
</script>
</head>
<body>
<form name="form" onsubmit="checking()">
<p>
Name: <input type="text" name="name">
<span style="color: red" id="name-error"></span>
</p>
<p>
Surname: <input type="text" name="surname">
<span style="color: red" id="surname-error"></span>
</p>
<p>Town: <input type="text" name="town"></p>
<p>Country: <input type="text" name="country"></p>
<p>
Postcode: <input type="text" name="postcode">
<span style="color:red" id="postcode-errro"></span>
</p>
<p>
E-mail: <input type="text" name="email">
<span style="color:red" id="email-error"></span>
</p>
<input type="submit" name="Send" value="Check">
</form>
</body>
</html>