JSP中email格式的判断

rain_ok 2002-05-15 09:45:51
加精
请问怎样才可以判断email的格式,就是判断有@符号,我用过
if(mail.indexOf('@')<=0)
out.println("email address wrong!");
但是不可以,还有就是咋可以让它限制用户注册时在email栏输入中文,小妹谢谢各位了
...全文
249 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
donny2000 2002-05-16
  • 打赏
  • 举报
回复
用正则表达式
HuangBin 2002-05-16
  • 打赏
  • 举报
回复
我给你个简单的:
public boolean isEmail(String email){
int pos;
pos=email.indexOf('@');
if (pos==-1)
return false;
else{
pos=email.indexOf('.');
if (pos==-1)
return false;
else
return true;
}
}
Andrawu 2002-05-16
  • 打赏
  • 举报
回复
此帖里有你想要的判断email的格式的方法。
http://www.csdn.net/expert/topic/654/654432.xml?temp=.3112146
Broadsea 2002-05-16
  • 打赏
  • 举报
回复
找到了!我自己的EMIAL校验就是参照SUN下面的例子做的。

Email Validation

The following code is a sample of some characters you can check are in an email address, or should not be in an email address. It is not a complete email validation program that checks for all possible email scenarios, but can be added to as needed.


/*
* Checks for invalid characters
* in email addresses
*/
public class EmailValidation {
public static void main(String[] args)
throws Exception {

String input = "@sun.com";
//Checks for email addresses starting with
//inappropriate symbols like dots or @ signs.
Pattern p = Pattern.compile("^\\.|^\\@");
Matcher m = p.matcher(input);
if (m.find())
System.err.println("Email addresses don't start" +
" with dots or @ signs.");
//Checks for email addresses that start with
//www. and prints a message if it does.
p = Pattern.compile("^www\\.");
m = p.matcher(input);
if (m.find()) {
System.out.println("Email addresses don't start" +
" with \"www.\", only web pages do.");
}
p = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#]+");
m = p.matcher(input);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
boolean deletedIllegalChars = false;

while(result) {
deletedIllegalChars = true;
m.appendReplacement(sb, "");
result = m.find();
}

// Add the last segment of input to the new String
m.appendTail(sb);

input = sb.toString();

if (deletedIllegalChars) {
System.out.println("It contained incorrect characters" +
" , such as spaces or commas.");
}
}
}
Broadsea 2002-05-16
  • 打赏
  • 举报
回复
没这么简单,java.sun.com上有标准的例程,如果需要的话,可以帮你找找。

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧