-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
50 lines (42 loc) · 1.26 KB
/
script.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
function checkform(theform){
var why = "";
if(theform.author_name.value == ""){
why += "- لا يمكنك ترك الاسم فارغ.\n";
}
if(theform.comment.value == ""){
why += "- لا يمكنك ارسال تعليق فارغ.\n";
}
if(theform.txtInput.value == ""){
why += "- لم تقم بإدخال رقم التحقق.\n";
}
if(theform.txtInput.value != ""){
if(ValidCaptcha(theform.txtInput.value) == false){
why += "- الأرقام التي ادخلتها خاطئة.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}
//Generates the captcha function
var code = '';
for(i=0; i<=4; i++){
code += Math.ceil(Math.random() * 9) + '';
}
document.getElementById("txtCaptcha").value = code;
document.getElementById("txtCaptchaDiv").innerHTML = code;
// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2){
return true;
}else{
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(' ').join('');
}