-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalid.js
133 lines (122 loc) · 4.47 KB
/
valid.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function validateFn(){
var firstName = document.getElementById('fName').value;
if(firstName.length == 0){
inputFieldChecks("First name is required", "fnLabel", "red");
firstName.ClassName = "fname";
return false;
}else if (!firstName.match(/^[A-Za-z]{1,20}\S\D\b$/g)) {
inputFieldChecks("Your first name should be between 3-20 characters long no digit(s), no space", "fnLabel", "red");
return false;
}else {
inputFieldChecks("✅", "fnLabel", "green");
return true;
}
}
function validateLn(){
var lastName = document.getElementById('lName').value;
if(lastName.length == 0){
inputFieldChecks("Last name is required", "lnLabel", "red");
return false;
}else if (!lastName.match(/^[A-Za-z]{1,20}\S\D\b$/g)) {
inputFieldChecks("Your Last name should be between 3-20 characters long no digit(s), no space", "lnLabel", "red");
return false;
}else {
inputFieldChecks("✅", "lnLabel", "green");
return true;
}
}
function validateTel(){
var telephone = document.getElementById('tel').value;
if(telephone.length == 0){
inputFieldChecks("A telephone number is required", "telLabel", "red");
return false;
}else if (!telephone.match(/^[(]{0,1}[0-9]{3}[)]{0,1}[0-9]{4}[-]{0,1}[0-9]{4}$/g)) {
inputFieldChecks("Your telephone number should have this format (000)0000-0000", "telLabel", "red");
return false;
}else {
inputFieldChecks("✅", "telLabel", "green");
return true;
}
}
function validateMob(){
var mobile = document.getElementById('mob').value;
if(mobile.length == 0){
inputFieldChecks("A mobile number is required", "mobLabel", "red");
return false;
}else if (!mobile.match(/^[(]{1}[+]{1}[0-9]{2,3}[)]{1}[0]{0}[0-9]{10}$/g)) {
inputFieldChecks("Your mobile number should have this format (+00)0000000000", "mobLabel", "red");
return false;
}else {
inputFieldChecks("✅", "mobLabel", "green");
return true;
}
}
function validateEmail(){
var email = document.getElementById('email').value;
if(email.length == 0){
inputFieldChecks("An email address is required", "emlLabel", "red");
return false;
}else if (!email.match(/^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-z0-9]+([a-z0-9-]*)\.)+[a-z]+$/g)) {
inputFieldChecks("Your mobile number should have this format (+00)0000000000", "emlLabel", "red");
return false;
}else {
inputFieldChecks("✅", "emlLabel", "green");
return true;
}
}
function validateFlat(){
var flat = document.getElementById('flatNo').value;
if(flat.length == 0){
inputFieldChecks("A flat number is required", "flatLabel", "red");
return false;
}else if (!flat.match(/^[0-9]{1,4}$/g)) {
inputFieldChecks("Your flat number should have the following format (01, 12, 123, 1234)", "flatLabel", "red");
return false;
}else {
inputFieldChecks("✅", "flatLabel", "green");
return true;
}
}
function validateAddress(){
var address = document.getElementById('line1').value;
if(address.length == 0){
inputFieldChecks("An address is required", "flatLabel", "red");
return false;
}else if (!address.match(/^([a-zA-Z,-]){0,50}\s?([a-zA-Z,-?]\s?){0,50}\S$/g)) {
inputFieldChecks("Your address should not end with a space and less than 100 characters", "addressLabel", "red");
return false;
}else {
inputFieldChecks("✅", "addressLabel", "green");
return true;
}
}
function validateCity(){
var city = document.getElementById('city').value;
if(city.length == 0){
inputFieldChecks("A city is required", "cityLabel", "red");
return false;
}else if (!city.match(/^[A-Za-z]{1,20}\S\D$/g)) {
inputFieldChecks("City should be between 3-20 characters long no digit(s), no space", "cityLabel", "red");
return false;
}else {
inputFieldChecks("✅", "cityLabel", "green");
return true;
}
}
function validatePc(){
var postcode = document.getElementById('pc').value;
if(postcode.length == 0){
inputFieldChecks("An postcode is required", "pcLabel", "red");
return false;
}else if (!postcode.match(/^[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,2}\s?[0-9]{1,2}[A-Z]{2}$/g)) {
inputFieldChecks("Your postcode should have the following format (AA1 5AA)", "pcLabel", "red");
return false;
}else {
inputFieldChecks("✅", "pcLabel", "green");
return true;
}
}
function inputFieldChecks(message, promptLocation, color){
document.getElementById(promptLocation).innerHTML = message;
document.getElementById(promptLocation).style.color = color;
}