Actionscript 3 提交前检查电子邮件值

Actionscript 3 提交前检查电子邮件值,actionscript-3,flash-cs6,Actionscript 3,Flash Cs6,在提交表单之前,我需要一个函数来检查@和符号 负责检查是否插入值的函数: // function ValidateAndSend function ValidateAndSend (event:MouseEvent):void { // validate fields if(!name_txt.length) { status_txt.text = "Please enter your name"; } else if (!email_txt.lengt

在提交表单之前,我需要一个函数来检查
@
符号

负责检查是否插入值的函数:

// 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

您应该为此使用正则表达式

您不需要checkEmail()函数

// function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
    var emailCheckRegExp:RegExp = /^[\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
    // validate fields
    if(name_txt.length == 0) {
        status_txt.text = "Please enter your name";
    } 
    else if (email_txt.length == 0) {
        status_txt.text = "Please enter your e-mail address";
    } 
    else if (phone_txt.length == 0) {
        status_txt.text = "Please enter your phone number";
    }
    else if(emailCheckRegExp.exec(email_txt.text) == null)
    {
        status_txt.text = "Entered e-mail is not valid";
    }
    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

检查电子邮件的函数似乎还可以,但您是否在
ValidateAndSend()
中调用了该函数?不,只是作为一个单独的函数。我正在对fl类型的值进行
隐式强制。控件:TextInput到一个不相关的类型字符串。
error.omg,抱歉,忘记添加文本字段的.text属性)现在更新,请检查是,它本该起作用的。非常感谢你的帮助库莫凯罗+一张向上的选票向你走来。