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
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Email id validation

Hi

How to check that the email id that we are entering is valid or not??

Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Email id validation

public class ValidatingEmailAddressEditField
    extends EmailAddressEditField
{
  // ...

  /**
   * Validates an email address. Checks that there is an "@"
   * in the field and that the address ends with a host that
   * has a "." with at least two other characters after it and
   * no ".." in it. More complex logic might do better.
   */
  public boolean isDataValid() {
    String address = getText();
    int at = address.indexOf("@");
    int len = address.length();
    if (at <= 0 || at > len - 6) return false;
    String host = address.substring(at + 1, len);
    len = host.length();
    if (host.indexOf("..") >= 0) return false;
    int dot = host.lastIndexOf(".");
    return (dot > 0 && dot <= len - 3);
  }
}
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Email id validation

[ Edited ]

Perhaps a better way of doing this is using the built-in email checking available for the BasicEditField,  So the Email input FIeld will be coded something like:

 

BasicEditField befCheckingForEmail = new BasicEditField("Email: ", "", 255, BasicEditField.FILTER_EMAIL);

 

If you want to implement checking for Fields like this, then I recommend you look at using a regular expression.  There is no regular expression library available on BlackBerry, but this one seems to work:

 

http://code.google.com/p/regexp-me/

 

Finally I recommend that you search the forum before asking questions.  Similar questions to this have been asked before, and you will find more robust email checking routines around, including this one:

 

http://supportforums.blackberry.com/t5/Java-Development/is-email-valid/m-p/2421455/highlight/true#M2...

Please use plain text.