@ validation for email in BlackBerry

徘徊边缘 提交于 2019-12-13 10:52: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.


回答1:


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

                 }
            }



回答2:


please try to use EmailAdressEditField class



来源:https://stackoverflow.com/questions/7580257/validation-for-email-in-blackberry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!