· 7 years ago · Jan 20, 2019, 07:52 PM
1function CheckFirstName() {
2 var FirstName = document.getElementById("First_Name").value; // gets the value the user types in the input field
3 var errFirstName = document.getElementById("errFirstName");
4 errFirstName.style.fontSize = "20px";
5 errFirstName.style.fontFamily = "Times New Roman";
6 //errFirstName.style.color = "darkred";
7 errFirstName.innerHTML = "";
8 if (FirstName.length < 2) {
9 errFirstName.innerHTML = "You must fill this section with at least 2 characters ";
10 return false; // returns that the value isn't valid
11 }
12 else if (FirstName.length > 10) {
13 errFirstName.innerHTML = "This section can not include more than 10 characters ";
14 return false; // returns that the value isn't valid
15 }
16 return true; // returns that the value is valid
17}
18
19function CheckLastName() {
20 var LastName = document.getElementById("Last_Name").value; // gets the value the user types in the input field
21 var errLastName = document.getElementById("errLastName");
22 errLastName.style.fontSize = "20px";
23 errLastName.style.fontFamily = "Times New Roman";
24 //errLastName.style.color = "darkred";
25 errLastName.innerHTML = " ";
26 if (LastName.length < 2) {
27 errLastName.innerHTML = "You must fill this section with at least 2 characters ";
28 return false; // returns that the value isn't valid
29 }
30 else if (LastName.length > 10) {
31 errLastName.innerHTML = "This section can not include more than 10 characters ";
32 return false; // returns that the value isn't valid
33 }
34 return true; // returns that the value is valid
35}
36
37function CheckEmail() {
38 var email = document.getElementById("Email").value; // gets the value the user types in the input field
39 var errEmail = document.getElementById("errMail");
40 var res2 = email.match(/@/gi); // search for a match of the character '@' in the email variable
41 var gmailCheck = new RegExp(/@gmail\.com$/g); // declares a new regualr expression '@gmail.com' that must be in the end of the string ($)
42 var res3 = gmailCheck.test(email); // checks for a match of the regualr string in the email
43 errEmail.style.fontSize = "20px";
44 errEmail.style.fontFamily = "Times New Roman";
45 //errEmail.style.color = "darkred";
46
47 errEmail.innerHTML = "";
48 if (email.search("@") == -1) {
49 errEmail.innerHTML = " The Email has no '@' sign in it";
50 return false; // returns that the value isn't valid
51 }
52 else if (res2.length > 1) {
53 errEmail.innerHTML = " The '@' sign exists more than once";
54 return false; // returns that the value isn't valid
55 }
56 else if (res3 == false) {
57 errEmail.innerHTML = " The email must include '@gmail.com' in the end";
58 return false; // returns that the value isn't valid
59 }
60 else if (email.length <= 10) {
61 errEmail.innerHTML = " The Email must have more than 10 characters";
62 return false; // returns that the value isn't valid
63 }
64 else if (email.length >= 30) {
65 errEmail.innerHTML = " The Email is too long";
66 return false; // returns that the value isn't valid
67 }
68 else {
69 return true; // returns that the value is valid
70 }
71}
72
73function CheckPass() {
74 var pass = document.getElementById("password").value; // gets the value the user types in the input field
75 var err = document.getElementById("errPassword");
76 err.innerHTML = "";
77 if (pass.length === 0) { // checks if the string is empty
78 err.innerHTML = "This is a required section ";
79 return false; // returns that the value isn't valid
80 }
81 else if (pass.length >= 21) { // checks if the string's length is as long as 21 characters
82 err.innerHTML = "The password can not include more than 20 characters ";
83 return false; // returns that the value isn't valid
84 }
85 return true; // returns that the value is valid
86}
87
88function PassStrength() {
89 var pass = document.getElementById("password").value; // gets the value the user types in the input field
90 var strengthPass = document.getElementById("PassStrength");
91 var sequence = false;
92 var speicalChCheck = new RegExp(/\W/g); // declaers a new regular expression which is not a character between 0-9 or a-z or A-Z
93 var speicalCharacters = speicalChCheck.test(pass); // Make a RegEx to check if there are speical characters like #, $, %, ^ and so on
94 console.log("speical characters value is " + speicalCharacters);
95 var numberExist = false;
96 for (var i = 0; i < pass.length; i++) { // checks for as long as the value's length if the character is a number or not
97 if (!isNaN(pass[i])) {
98 numberExist = true;
99 }
100 }
101
102 for (var i = 0; i < pass.length; i++) {// checks if there is a rising\decreasing sequence (a series of numbers which the when you subtract from one another you get the same value)
103 if (!isNaN(pass[i]) && !isNaN(pass[i + 1]) && !isNaN(pass[i + 2])) {
104 if (pass[i] - pass[i + 1] == pass[i + 1] - pass[i + 2]) {
105 sequence = true; console.log(pass[i], pass[i + 1], pass[i + 2]);
106 console.log(sequence);
107 }
108 }
109 }
110
111 strengthPass.innerHTML = "";
112 if (pass.length === 0) {
113 strengthPass.innerHTML = " You must fill the password section ";
114 return false; // returns that the value isn't valid
115 }
116 else if (numberExist === true && pass.length >= 5) {
117 strengthPass.innerHTML = " This password is still preety weak ";
118 }
119 else if (pass.length <= 5) {
120 strengthPass.innerHTML = " This password is very weak ";
121 }
122 else if (sequence = true && pass.length >= 7) { // the sequance is stornger than numberExist because it requires at least 3 numbers
123 strengthPass.innerHTML = " This password is a medium password ";
124 }
125 else if (sequence === false && numberExist === true && pass.length >= 8) {
126 strengthPass.innerHTML = " This is a strong password ";
127 }
128}
129function CheckFather() {
130 var val = document.getElementById("fatherName").value; // gets the value the user types in the input field
131 var err = document.getElementById("errFather");
132 var BigCH = new RegExp(/^[A-Z]/); // declares a new regualr expression which is a character between A-Z in the begining of the string
133 err.innerHTML = "";
134 if (val.length < 2) {
135 err.innerHTML = "You must fill this section with at least 2 characters ";
136 return false; // returns that the value isn't valid
137 }
138 else if (BigCH.test(val) === false) {
139 err.innerHTML = "You must start a name with a capital letter ";
140 return false; // returns that the value isn't valid
141 }
142 else if (val.length >= 10) {
143 err.innerHTML = "This section can not include more than 10 characters ";
144 return false; // returns that the value isn't valid
145 }
146 else if (!isNaN(val)) {
147 err.innerHTML = "You can not fill this section with numbers ";
148 return false; // returns that the value isn't valid
149 }
150 else if (val.length === 0) {
151 return false; // returns that the value isn't valid
152 }
153 return true; // returns that the value is valid
154}
155
156function CheckMother() {
157 var val = document.getElementById("motherName").value; // gets the value the user types in the input field
158 var err = document.getElementById("errMother");
159 var BigCH = new RegExp(/^[A-Z]/); // declares a new regualr expression which is a character between A-Z in the begining of the string
160 err.innerHTML = "";
161 if (val.length < 2) {
162 err.innerHTML = "You must fill this section with at least 2 characters ";
163 return false; // returns that the value isn't valid
164 }
165 else if (BigCH.test(val) === false) {
166 err.innerHTML = "You must start a name with a capital letter ";
167 return false; // returns that the value isn't valid
168 }
169 else if (val.length >= 10) {
170 err.innerHTML = "This section can not include more than 10 characters ";
171 return false; // returns that the value isn't valid
172 }
173 else if (!isNaN(val)) {
174 err.innerHTML = "You can not fill this section with numbers ";
175 return false; // returns that the value isn't valid
176 }
177 else if (val.length === 0) {
178 return false; // returns that the value isn't valid
179 }
180 else {
181 return true; // returns that the value is valid
182 }
183}
184
185function CheckPhone() {
186 var phoneNumber = document.getElementById("Phone_Number").value; // gets the value the user types in the input field
187 var err = document.getElementById("errPhone");
188 var start = new RegExp(/^([+972]{4}|05)/); // declares a new regualar expression which is either +972 or 05 in the begining
189 // can include \d{9} to check if has the right number of characters after (or ^([+972|05]){1,4} )
190 err.innerHTML = "";
191 if (isNaN(phoneNumber)) { // checks if the phone number includes character
192 err.innerHTML = "A phone number includes only numbers (not characters) ";
193 return false; // returns that the value isn't valid
194 }
195 else if (start.test(phoneNumber) === false) {
196 err.innerHTML = "A phone number must start with 05 or +972 ";
197 return false; // returns that the value isn't valid
198 }
199 else if (phoneNumber.length != 10 && phoneNumber.length != 13) {
200 err.innerHTML = "There must 10 numbers in the phone number ";
201 return false; // returns that the value isn't valid
202 }
203 else if (phoneNumber.length === 0) {
204 alert("phoneNumber.length === 0 is " + phoneNumber.length === 0);
205 return false; // returns that the value isn't valid
206 }
207 return true; // returns that the value is valid
208}
209
210function AgeCheck2() {
211 var UserDate = document.getElementById("BDay").value; // gets the value the user types in the input field /*alert("User Date is " + UserDate); */
212 var err = document.getElementById("errBDay");
213 var today = new Date(); // declares a new variable that gets the current date /*alert("today is " + today);*/
214 var year = today.getFullYear(); // get the current year //alert("Year is " + year);
215 var month = today.getMonth() + 1; // get tehe current month /*alert("Month is " + month);*/
216 var day = today.getDate(); // get the current day /*alert("Day is " + day); */
217
218 var Useryear = UserDate.slice(0, UserDate.indexOf("-")); // get user's birthday year /*alert("Useryear: " + Useryear); */
219 var Usermonth = UserDate.slice(UserDate.indexOf("-") + 1, UserDate.lastIndexOf("-")); // get user's birthday month /*alert("Usermonth: " + Usermonth); */
220 var Userday = UserDate.slice(UserDate.lastIndexOf("-") + 1); // get user's birthday day /*alert("Userday: " + Userday); */
221
222 err.innerHTML = "";
223
224 if (Useryear < year - 13) {
225 err.innerHTML = "Age is ok";
226 return true;
227 }
228 else if (Useryear == year - 13) {
229 if (Usermonth < month) {
230 err.innerHTML = "Age is ok";
231 return true;
232 }
233 else if (Usermonth === month && Userday <= day) {
234 err.innerHTML = "Age is ok";
235 return true;
236 }
237 else {
238 err.innerHTML = "Houston we have a problem - you must be above 13 years old";
239 return false;
240 }
241 }
242 else {
243 err.innerHTML = "Houston we have a problem - you must be above 13 years old";
244 return false;
245 }
246}
247
248function Captha() {
249 var response = grecaptcha.getResponse(); // gets the respone from the captcha form
250 var check = false;
251 var repeatCheck = setInterval(Captha, 1000); // repeats the action every second
252 console.log(repeatCheck);
253 if (response.length == 0) { // if the captcha is unsuccessful it returns an empty string ("")
254 document.getElementById("errCapatcha").innerHTML = " Prove you are not a robot";
255 return false;
256 } else {
257 document.getElementById("errCapatcha").innerHTML = " You are good to go";
258 clearInterval(repeatCheck); // stops the repeat of the action
259 return true;
260 }
261}
262
263function AllChecks() { // checks if the all functions are corect
264 return CheckFirstName() && CheckLastName() && CheckEmail() && CheckPass()
265 && CheckFather() && AgeCheck2() && CheckMother() && CheckPhone() && Captha();
266}