0

I can't figure out what I am doing wrong with this function for livecycle checking the email address. Livecycle console returns an error of "ReferenceError: emailAddress not defined" even though the function will fire the alert or xfa.host.messageBox. Can you tell me why the global variable emailAddress can't be defined after running through this function. Thanks for your time.

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);
bfavaretto
  • 71,580
  • 16
  • 111
  • 150
Greg
  • 63
  • 2
  • 4
  • 11

1 Answers1

2

The emailAddress variable only exists inside the function, but you're trying to access it from the outside. It's out of scope. Not sure what you're looking for, maybe this?

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);
bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • Ahh I am trying to check the e-mail address of a textfield. If the value doesn't match to the RegExp variable then the function returns a cleared value. – Greg Jun 21 '13 at 17:53
  • So the above should work, right? Another problem you had was that `var emailAddress` inside the function prevented you from reading the `emailAddress` argumento you were passing. – bfavaretto Jun 21 '13 at 17:55