javascript - LiveCycle Javascript 函数引用错误

标签 javascript regex function email livecycle

我无法弄清楚这个用于实时检查电子邮件地址的功能做错了什么。即使该函数将触发警报或 xfa.host.messageBox,Livecycle 控制台也会返回“ReferenceError:emailAddress 未定义”错误。你能告诉我为什么运行此函数后无法定义全局变量 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);

最佳答案

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);

关于javascript - LiveCycle Javascript 函数引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17241224/

相关文章:

c++ - 在 C++ 中显式调用原始运算符函数

c# - 如何从 Azure Function (HTTP) 返回数据流

javascript - 在 ionic 2 中滑动或单击按钮的 div

javascript - 防止默认滚动到输入元素

javascript - 将 float 作为自然数排序

regex - 最新的 Perl 不会匹配某些长度超过 32768 个字符的正则表达式

sql - PostgreSQL 中的字符串模式匹配

regex - 正则表达式和字符串操作

function - 在 Lisp 中编写递归 GCD

javascript - MatchMedia.js 是否包含在 Modernizr JS 中?