-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (40 loc) · 1.04 KB
/
index.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
function formValidation() {
//Make references to fields
var name = document.getElementById('name');
var email = document.getElementById('_replyto');
var message = document.getElementById('message');
//Reset alert
$('#alert').text("");
//Check if form fields are empty
if(name.value.length == 0) {
$('#alert').text("Please fill in all fields.");
name.focus();
return false;
}
if(_replyto.value.length == 0) {
$('#alert').text("Please fill in all fields.");
_replyto.focus();
return false;
}
if(message.value.length == 0) {
$('#alert').text("Please fill in all fields.");
message.focus();
return false;
}
//Check if email entered is valid
if(emailValidation(email)){
return true;
}
}
//Validate email using regex
function emailValidation(inputtext) {
var emailExp = /^[\w\-\.\_]{1,20}\@[a-zA-Z0-9\.\-]{1,20}\.[a-zA-Z]{2,4}$/;
if (inputtext.value.match(emailExp)) {
return true;
}
else {
$('#alert').text("Invalid Email.");
inputtext.focus();
return false;
}
}