AX2012 X++ Code validate the email id


// Create a job and paste the below code ..

static void RB_validateEmail(Args _args)
{
   
    Str     email;
    Str     MatchEmailPattern =@"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b";
    System.Text.RegularExpressions.Match myMatch;
   
    ;
    email = "rameshAX2012@gmail.com";
    myMatch = System.Text.RegularExpressions.Regex::Match(email, MatchEmailPattern);

    if (myMatch.get_Success())
        info(strFmt("%1 is an valid email id ", email));
    else
       info(strFmt("%1 is not an valid email id ", email));
}

3 comments:

  1. can you please explain this line of the code
    {
    Str MatchEmailPattern =@"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b";
    }

    ReplyDelete
  2. Your snippet worked like a charm ! Thanks for developing it and for sharing it !

    ReplyDelete
  3. it not working for these emails: 'a@c.comm', 'a@c.co', 'a@c.coom'

    ReplyDelete