@ validation for email in BlackBerry

2019-09-23 08:37发布

I am developing a form where the user needs to enter a valid email. He/she will use it as a loginid to play the game.I want to know how can I validate the username containing @, similar to string.contains function. I learnt we can use string.indexOf() but it is not supporting "@". Kindly suggest how do I carry out this validation. When the email editfield loses focus, the username must be checked to see if it contains "@" or not.

2条回答
我想做一个坏孩纸
2楼-- · 2019-09-23 08:48
做个烂人
3楼-- · 2019-09-23 09:10

Use EmailAddressEditField.. here is the way

EmailAddressEditField email=new EmailAddressEditField("Email Address: ", "");
        String address =email.getText();
            int at = address.indexOf("@");
            int len = address.length();
            String host = address.substring(at + 1, len);
            int dot = host.lastIndexOf('.');
            len = host.length();

            if (at <= 0 || at > len - 6  && dot < 0 || dot >= len - 3)
                Dialog.alert("Invalid email");
            else
            {
                 if (host.indexOf("..") >= 0)
                 {
                     Dialog.alert("Invalid email");
                 }
                 else
                 {
                     //correct mail id.. continue your process

                 }
            }
查看更多
登录 后发表回答