-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (40 loc) · 1.36 KB
/
Copy pathscript.js
File metadata and controls
41 lines (40 loc) · 1.36 KB
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
$(document).ready(function(){
$('#mainform input,#mainform textarea').on("focus",function(){
$(this).siblings('.error_message').hide();
$(this).attr('class','active');
});
$('#mainform input,#mainform textarea').on("blur",function(){
if($(this).val()==""){
$(this).siblings('.error_message').fadeIn(350);
$(this).attr('class','danger');
}
});
$("#mainform").on("submit",function(e){
var toSubmit=true;
e.preventDefault();
$('#mainform input,#mainform textarea').each(function(){
var $element=$(this);
if($element.val()==''){
$element.attr('class','danger');
$element.siblings('.error_message').fadeIn(350);
toSubmit=false;
return;
}
if($element.attr('type')=='email'){
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var isValidEmailAddress = re.test($element.val());
if(!isValidEmailAddress){
$element.attr('class','danger');
$element.siblings('.error_message').fadeIn(350);
toSubmit=false;
return;
}
}
$element.removeClass('error');
$element.siblings('.error-message').hide();
});
if(toSubmit){
console.log("Form submitted");
}
});
});