在提交表单之前,我需要一个函数来检查@
和.
符号。
负责检查值是否被插入的函数:
// function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
// validate fields
if(!name_txt.length) {
status_txt.text = "Please enter your name";
} else if (!email_txt.length) {
status_txt.text = "Please enter your e-mail address";
} else if (!phone_txt.length) {
status_txt.text = "Please enter your phone number";
} else {
// All is good, send the data now to PHP
// ready the variables in our form for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userPhone = phone_txt.text;
variables.userShop = shopList.value;
// Send the data to PHP now
varLoader.load(varSend);
} // close else condition for error handling
} // close validate and send function
我尝试创建一个单独的函数来检查电子邮件符号:
// Checking e-mail
function checkEmail():Boolean {
var reEmail:String = email_txt.text;
var emailOk:Boolean = false;
var checkArray1:Array = reEmail.split("@");
if (checkArray1.length >1) {
var checkArray2:Array = checkArray1[1].split(".");
if (checkArray2.length >1) {
emailOk = true;
}
}
return emailOk;
}
但这不起作用。您将如何实现这一目标?
更新:我试过在函数内部运行ValidateAndSend
函数。但是现在如果电子邮件地址错误,它不会发送消息,但仍会显示成功提交消息。
// function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
// validate fields
if(!name_txt.length) {
status_txt.text = "Please enter your name";
} else if (!email_txt.length) {
status_txt.text = "Please enter your e-mail";
// Checking e-mail
function checkEmail():Boolean {
var reEmail:String = email_txt.text;
var emailOk:Boolean = false;
var checkArray1:Array = reEmail.split("@");
if (checkArray1.length >1) {
status_txt.text = "Please check your e-mail address";
var checkArray2:Array = checkArray1[1].split(".");
if (checkArray2.length >1) {
emailOk = true;
}
}
return emailOk;
}
} else if (!phone_txt.length) {
status_txt.text = "Please enter your phone number";
} else {
// All is good, send the data now to PHP
// ready the variables in our form for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userPhone = phone_txt.text;
variables.userShop = shopList.value;
// Send the data to PHP now
varLoader.load(varSend);
} // close else condition for error handling
} // close validate and send function