-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartJava.js
More file actions
110 lines (99 loc) · 3.21 KB
/
CartJava.js
File metadata and controls
110 lines (99 loc) · 3.21 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
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
function validatePersonalInfo()
{
var _first = document.info.fname.value;
var _street = document.info.street.value;
var _street2 = document.info.street2.value;
var _city = document.info.city.value;
var _zip = document.info.zip.value;
var _phone = document.info.phone.value;
var _email = document.info.email.value;
if(_first.toString() == ""){console.log("Please enter a full name.");}
if(_street.toString() == ""){console.log("Please enter your street name.");}
if(_city.toString() == ""){console.log("Please enter your city.");}
if(_zip.toString() == ""){console.log("Please enter your zip.");}
if(_phone.toString() == ""){console.log("Please enter your phone number.");}
if(_email.toString() == ""){console.log("Please enter your email.");}
stringlength(_first.toString(),0,100);
stringlength(_street.toString(),0,100);
stringlength(_zip.toString(),0,100);
stringlength(_phone.toString(),0,100);
stringlength(_email.toString(),0,100);
var checkZip = checkNum(5);
var phoneInput = document.info.phone.value;
var validPhone = false;
var validZip = false;
if(checkZip == true){
validZip = true;
}
else{
console.log("Invalid Zip Code" + validZip);
}
if(!checkPhone(phoneInput)){
console.log("Phone number is invalid." + validPhone);
}
else{
validPhone = true;
}
if(validZip && validPhone){
console.log("Your form has been verified");
}
}
function checkPhone(str)
{
var regexp = /^(\d{10}|\d{3}-\d{3}-\d{4}|\(\d{3}\)\d{3}-\d{4})$/;
return regexp.test(str);
}
// function to validate date
function checkDate(str)
{
var re = /^(\d{1,2}\/\d{4})$/;
if(form.startdate.value != '' && !form.expdate.value.match(re)) {
alert("Invalid date format: " + form.expdate.value);
form.expdate.focus();
return false;
}
function checkNum(length){
var zipEntry = document.info.zip.value;
var zipNum = parseInt(zipEntry, 12);
if (document.info.zip.value.length == length){
if(zipNum != 0 && isNaN(zipNum) == false){
return true;
}
else {
return false;
}
}
else {
return false;
}
}
function checkMail(str)
{
var regexp = /^(([^<>()\[\]\\.,;:\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,}))$/;
return regexp.test(str);
}
function stringlength(inputtxt, minlength, maxlength)
{
var field = inputtxt.value;
var mnlen = minlength;
var mxlen = maxlength;
if(field.length<mnlen || field.length> mxlen)
{
alert("Please input between " +mnlen+ " and " +mxlen+ " characters");
return false;
}
else
{
alert('Form Saved');
return true;
}
//function to submit form
function SubmitForm()
{
document.form1.submit();
}
//function to check form
function checkForm(form1)
{
if(!checkDate(form.expdate)) return false;
}