0

我无法弄清楚我在使用这个函数来检查电子邮件地址时做错了什么。Livecycle 控制台返回“ReferenceError:未定义电子邮件地址”错误,即使该函数将触发警报或 xfa.host.messageBox。你能告诉我为什么在运行这个函数后无法定义全局变量 emailAddress 吗?谢谢你的时间。

function fxemailverification(emailAddress) {

    var r = new RegExp("^[A-Za-z0-9_\\-\\.]+\\@test.com");

    // Test the rawValue of the current object to see if it matches the new RegExp
    var result = r.test(emailAddress); 

    if (result == false) {
        var emailAddress = "";
        alert("You have entered an invalid Email address. \nAll email addresses must end in '@test.com'.", "Email Verification", 4, 0);
    }
    return emailAddress;
};

textfield1.rawValue = fxemailverification(emailAddress);
4

1 回答 1

2

emailAddress变量仅存在于函数内部,但您试图从外部访问它。它超出了范围。不知道你在找什么,也许是这个?

var emailAddress = "";
function fxemailverification(emailAddress) {
    var r = new RegExp("^[A-Za-z0-9_\\-\\.]+\\@test.com");
    // Test the rawValue of the current object to see if it matches the new RegExp
    var result = r.test(emailAddress); 

    if (result == false) {
        emailAddress = "";
        alert("You have entered an invalid Email address. \nAll email addresses must end in '@test.com'.", "Email Verification", 4, 0);
    }
    return emailAddress;
};

textfield1.rawValue = fxemailverification(emailAddress);
于 2013-06-21T17:41:59.020 回答