-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (113 loc) · 3.54 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
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
134
135
136
137
var username,phone,email,comment;
function nameValidate(){
var namevalue=$('#name').val()
var letters = /^[-a-zA-Z-()]+(\s+[-a-zA-Z-()]+)*$/
if(namevalue==""){
$("#name-error").html("Field is required")
$('#name').css({'border':'solid 1px red'})
username= false
}
else if(namevalue.match(letters)){
$('#name-error').html("")
$('#name').css({'border':'solid 1px black'})
username=true
}
}
function phoneValidate(){
var namevalue=$('#phone').val()
var letters = /^\d+$/;
if(namevalue=="" || namevalue==" "){
$('#phone-error').html("Field is required")
$('#phone').css({'border':'solid 1px red'})
phone= false
}
else if(namevalue.match(letters) && ( namevalue.length == 10))
{
console.log("jndf")
$("#phone-error").html("")
$('#phone').css({'border':'solid 1px black'})
phone= true
}
else if(namevalue.length<10)
{
if(namevalue.match(letters))
{
$("#phone-error").html("Invalid phone number!!")
$('#phone').css({'border':'solid 1px black'})
phone= false;
}
}
else if(namevalue.length>10)
{
if(namevalue.match(letters))
{
$("#phone-error").html("Only ten numbers allowed")
$('#phone').css({'border':'solid 1px red'})
phone=false;
}
else
{
$("#phone-error").html("Use only numbers")
$('#phone').css({'border':'solid 1px red'})
phone= false;
}
}
else{
$("#phone-error").html("Invalid number")
$('#phone').css({'border':'solid 1px red'})
phone=false;
}
}
function emailValidate(){
var emailvalue =$('#email').val()
var letters = /^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)$/;
if(emailvalue==""){
$('#email-error').html("Filed is required")
$('#email').css({'border':'solid 1px red'})
email=false;
}
else if(emailvalue==" "){
$('#email-error').html("Do not enter space as first character")
$('#email').css({'border':'solid 1px red'})
username=false
}
else if(emailvalue.match(letters)){
$('#email-error').html("")
$('#email').css({'border':'solid 1px black'})
email=true;
}
else{
$('#email-error').html("Invalid Entry")
$('#email').css({'border':'solid 1px red'})
email=false;
}
}
$('.navbar-collapse a').click(function(){
$(".navbar-collapse").collapse('hide');
});
$("#gform").submit((e)=>{
e.preventDefault()
if (username==true && email==true && phone==true) {
$.ajax({
url:"https://script.google.com/macros/s/AKfycbwPmyAUPzqWhRYy22lzFnpvfjmyTLPZmcfIXe3j4vzVm99R4RKknO7yIwIL_qgL4kkrTw/exec",
data:$("#gform").serialize(),
method:"post",
success:function (response){
alert("Successfully submitted")
// alert({title:"Good job!", text:"Your message send successfully", icon:"success"},function(){
// window.location.reload()
// });
window.location.reload()
//window.location.href="https://google.com"
},
error:function (err){
alert("Something Error")
}
})
}else{
nameValidate()
phoneValidate()
emailValidate()
commentValidate()
}
})