-
Notifications
You must be signed in to change notification settings - Fork 0
/
checks.js
87 lines (86 loc) · 2.28 KB
/
checks.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
function isEmailAddr(elem)
{
var str = elem.value;
str = str.toLowerCase();
if (str.indexOf("@") > 1)
{
var addr = str.substring(0,str.indexOf("@"));
var domain = str.substring(str.indexOf("@") + 1,str.length);
if (domain.indexOf(".") == -1)
{
alert("Verify the domain portion of the email address.");
return false;
}
for ( var i=0; i<addr.length; i++ )
{
oneChar = addr.charAt(i).charCodeAt(0);
if ((i==0 && (oneChar==45 || oneChar==46)) ||
(i==addr.length-1 && oneChar==46))
{
alert("Verify the user name portion of the email address.");
return false;
}
if ( oneChar==45 || oneChar==46 || oneChar==95 ||
(oneChar>47 && oneChar<58) || (oneChar>96 && oneChar<123))
{
continue;
}
else
{
alert("Verify the user name portion of the email address.");
return false;
}
}
for ( i=0; i<domain.length; i++ )
{
oneChar = domain.charAt(i).charCodeAt(0);
if ((i==0 && (oneChar==45 || oneChar==46)) ||
((i==domain.length-1 || i==domain.length-2) && oneChar==46))
{
alert("Verify the domain portion of the email address.");
return false;
}
if (oneChar==45 || oneChar==46 || oneChar==95 ||
(oneChar>47 && oneChar<58) || (oneChar>96 && oneChar<123))
{
continue;
}
else
{
alert("Verify the domain portion of the email address.");
return false;
}
}
return true;
}
alert("The email address may not be formatted correctly. Please verify.");
return false;
}
function isNotEmpty(elem)
{
var str = elem.value;
var re = /.+/;
if (!str.match(re))
{
alert("Please fill in the required field.");
return false;
}
else
{
return true;
}
}
function validateForm( form )
{
if (isNotEmpty(form.call))
{
if (isNotEmpty(form.email))
{
if (isEmailAddr(form.email))
{
return true;
}
}
}
return false;
}