我有一个论坛,可以在提交时调用一些函数。 javascript看起来像这样:
function validateForm() {
var x=document.forms["checkout"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
var x=document.forms["checkout"]["lname"].value;
if (x==null || x=="")
{
alert("Last name must be filled out");
return false;
}
var x=document.forms["checkout"]["address"].value;
if (x==null || x=="")
{
alert("Address must be filled out");
return false;
}
var x=document.forms["checkout"]["email"].value;
if (x==null || x=="")
{
alert("Email address must be filled out");
return false;
}
var x=document.forms["checkout"]["phone"].value;
if (x==null || x=="")
{
alert("Phone number must be filled out");
return false;
}
var x=document.forms["checkout"]["card"].value;
if (x==null || x=="")
{
alert("Credit card info must be filled out");
return false;
}
}
function validateEmail(email) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@@\[?((25[0- 5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.) {2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(email);
}
function validatePhone(phone) {
var ppattern = new RegExp(/^[\d ]+$/);
return ppattern.test(phone);
}
function validateCard(card) {
var cpattern = new RegExp(/(?:\d[ ]?){12,17}\d/);
return cpattern.test(card);
}
如何在有效的论坛提交时(在检查所有javascript函数有效后)将其重定向到构造页面?
答案 0 :(得分:0)
function validation() {
// validation stuff here
if (validated) { redirect('url here'); }
}
function redirect(url) {
window.location.href = url;
}