1 function placeOrder(form){
2 if(validateLength(1,32,form["message"],form["message_help"])&&
3 validateZIPCode(form["location"],form["location_help"])&&
4 validateLength(1,32,form["date"],form["date_help"])&&
5 validateLength(1,32,form["name"],form["name_help"])&&
6 validateLength(1,32,form["phone"],form["phone_help"])&&
7 validateLength(1,32,form["email"],form["email_help"])){
8 alert("1");
9 form.submit();
10 }
11 else{
12 alert("I'm sorry but there something wrong with the order information.");
13 }
14 }
15 function validateNonEmpty(inputFeild,helpText){
16 if(inputFeild.value.length==0){
17 if(helpText!=null)
18 helpText.innerHTML="please enter the data.";
19 return false;
20 }
21 else{
22 if(helpText!=null)
23 helpText.innerHTML="";
24 return true;
25 }
26 }
27 function validateLength(MinLength,MaxLength,inputFeild,helpText){
28 if(inputFeild.value.length<MinLength||inputFeild.value.length>MaxLength){
29 //È·ÈÏhelpTextÔªËصĴæÔÚ
30 if(helpText!=null)
31 helpText.innerHTML="Please enter the data between 1 to 32.";
32 return false;
33 }
34 else{
35 if(helpText!=null)
36 helpText.innerHTML="";
37 return true;
38 }
39 }
40 function validateZIPCode(inputFeild,helpText){
41 if(!validateNonEmpty(inputFeild,helpText))
42 return false;
43 else{
44 return validateRegEx(/^d{5}$/,inputFeild.value,helpText,"please enter exactly five digits. ");
45 }
46 /*if(inputFeild.value.length!=5){
47 //È·ÈÏhelpTextÔªËصĴæÔÚ
48 if(helpText!=null)
49 helpText.innerHTML="Please enter exactly five digits.";
50 return false;
51 }
52 else if(isNaN(inputFeild.value)){
53 if(helpText!=null)
54 helpText.innerHTML="please enter a number.";
55 return false;
56 }
57 else{
58 if(helpText!=null)
59 helpText.innerHTML="";
60 return true;
61 }*/
62
63 }
64 function validateDate(inputFeild,helpText){
65 if(!validateNonEmpty(inputFeild,helpText))
66 return false;
67 else{
68 return validateRegEx(/^d{2}d{2}d{4}$/,inputFeild.value,helpText,"please enter a date(for example:02/02/2016). ");
69 }
70 }
71 function validatePhone(inputFeild,helpText){
72 if(!validateNonEmpty(inputFeild,helpText))
73 return false;
74 else{
75 return validateRegEx(/^(15|13|17)d{10}$/,inputFeild.value,helpText,"please enter your number(for example:15023698251). ");
76 }
77 }
78 function validateEmail(inputFeild,helpText){
79 if(!validateNonEmpty(inputFeild,helpText))
80 return false;
81 else{
82 return validateRegEx(/^[w.-_+]+@[.w{2,3}]+$/,inputFeild.value,helpText,"please enter your email address(for example:2536966@qq.com). ");
83 }
84 }
85 function validateRegEx(regex,inputStr,helpText,helpMessage)
86 {
87 if(!regex.test(inputStr)){
88 if(helpText!=null)
89 helpText.innerHTML=helpMessage;
90 return false;
91 }
92 else{
93 if(helpText!=null)
94 helpText.innerHTML="";
95 return true;
96 }
97 }