ActionScript Email Validation

Sooner or later you will face with the small quest of validating an email address for your flash application. The following script is a basic script and should not be used for websites that relay heavily on the email address is being requested (shopping carts, credit card transactions and so forth)

ActionScript:
    function isValidEmail(e) {
    if (e.indexOf("@") != -1 && ( e.indexOf(".") > e.indexOf("@") ) ){
    trace("success");
    }else{
    trace("error");
    }
    }

    //Test
    isValidEmail("test@test.com");

7 Responses to “ActionScript Email Validation”

  1. Mohammed Zainal June 11, 2007 at 7:11 am # Reply

    very good one but what if you got an email like me.u@gmail.com ?
    it will return it false …

    any idea ?

  2. Anonymous August 14, 2007 at 3:10 am # Reply

    How about like this ???
    if (e.indexOf(“@”) != -1 && ( e.lastIndexOf(“.”) > e.indexOf(“@”) ) ) {
    trace(“success”);
    }else{
    trace(“error”);
    }

  3. Anonymous August 14, 2007 at 3:29 am # Reply


    // a minimum a@a.us is require
    if ((emailString.indexOf("@") > 0) &&
    (emailString.lastIndexOf(".") > (emailString.indexOf("@") + 1)) &&
    (emailString.lastIndexOf(".")

  4. Anonymous August 14, 2007 at 3:40 am # Reply


    // minimum a@a.us
    if ((e.indexOf("@") > 0) &&
    (e.lastIndexOf(".") > (e.indexOf("@") + 1)) &&
    (e.lastIndexOf(".")

  5. chandramani April 10, 2008 at 1:16 am # Reply

    Hello,

    i want email validation with flash action script which i have
    apply here the code :

    validate_btn.onRelease = function() {
    indexOfAt = email.text.indexOf(“@”);
    lastIndexOfDot = email.text.lastIndexOf(“.”);
    if (indexOfAt != -1 && lastIndexOfDot != -1) {
    if (lastIndexOfDot

  6. dfm May 27, 2008 at 9:43 am # Reply

    [code]
    function is_valid_email(email:String):Boolean {
    var emailRgx:RegExp = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    ///^[a-zA-Z0-9][-._a-zA-Z0-9]*@([a-zA-Z0-9]*.)+[a-zA-Z]{2,6}$/;
    trace(emailRgx.test(email));
    return emailRgx.test(email);
    }
    is_valid_email("c@j.co");
    [/code]

  7. Pradeep December 9, 2009 at 2:47 am # Reply

    Do we need to inport any thing like – import RegExp; for the above code to work?

Leave a Reply