@验证在BlackBerry电子邮件 [英] @ validation for email in BlackBerry
本文介绍了@验证在BlackBerry电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发展,用户需要输入一个有效的电子邮件的形式。他/她将使用它作为一个登录ID玩game.I想知道我怎么可以验证包含@用户名,类似于string.contains功能。我了解到,我们可以使用string.indexOf(),但它是不支持@。请建议我怎么开展这项验证。当电子邮件EditField中失去焦点,用户名必须进行检查,看它是否包含@与否。
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.
推荐答案
使用EmailAddressEditField ..这里是这样的。
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
}
}
这篇关于@验证在BlackBerry电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文