Skip to main content
Manish pol ha fatto una domanda in #Formulas
Hi All,

Could anyone help me to write email validation.

Below these Email format should not be included

Invalid email addresses

Abc.example.com (no @ character)

234567890123456789012345678901234567890123456789012345678901734+x@example.com (too long)

john..doe@example.com (double dot before @)

example@localhost (sent from localhost)

john.doe@example..com (double dot after @)

john..doe@example.com

Please help me guys.

​Thanks in advance
1 risposta
  1. 1 mar 2018, 23:19
    String emailString = 'testemail@localhost..com';

    Boolean validemail = true;

    if(!emailString.contains('@'))

    {

         if(emailString.substringAfter('@').contain('localhost'))

         {

             validemail  = false;

          }

          if(emailString.substringAfter('@').contain('..'))

         {

              validemail  = false;

         }

         if(emailString.substringBefore('@').contain('..'))

         {

              validemail  = false;

         }

    }else

    {

            validemail = false;

    }

    if(!validemail )

    {

    addError

    }

    You need to use https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm to cover all your scenarios

     
0/9000