Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 77
Registered: ‎05-21-2012
My Device: 9900

Re: Proper email validation

Hi lakshman

 

I tried a snippet of your code along with answer provided by Pankaj

 

On using this code given below i am able to validate for "." at end of string

eg: abc@gmail.com. gives me a validation error

 

private static boolean lastEmailFieldTwoCharsOrMore(String emailAddress) 
    { 
        int lastIndex = emailAddress.lastIndexOf('.');
        String lastToken = emailAddress.substring(lastIndex + 1);
        if (lastToken.length() >= 2) 
        {
            if (lastToken.length() <= 3)
             {
                return true;
             } 
            else 
            {
                return false;
            }
        } 
        else 
        {
            return false;
        }
    }

 

 

Can you guide me how i can manipulate this same code for testing for the position of  "." at start.

eg:   .abc@gmail.com

 

Regards,

Techie 

Highlighted
Developer
Posts: 243
Registered: ‎07-22-2011
My Device: BlackBerry Z10
My Carrier: AirTel

Re: Proper email validation

Hi,

 

ok, change above method to this and try...

 

 

 

private static boolean lastEmailFieldTwoCharsOrMore(String emailAddress) 
    { 
        if(emailAddress.startsWith("."))
            return false;
        int lastIndex = emailAddress.lastIndexOf('.');
        String lastToken = emailAddress.substring(lastIndex + 1);
        if (lastToken.length() >= 2) 
        {
            if (lastToken.length() <= 3)
             {
                return true;
             } 
            else 
            {
                return false;
            }
        } 
        else 
        {
            return false;
        }
    }

 

 

 

 

 

Regards,

Lakshman K

 

----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

Regular Contributor
Posts: 77
Registered: ‎05-21-2012
My Device: 9900

Re: Proper email validation

Thank you so much Lakshman and Pankaj.