验证邮箱格式的正则表达式(Struts)

Posted on 2006-12-28 11:58 阅读(1289) 评论(0)  编辑  收藏
 public ActionErrors validate(ActionMapping actionMapping,
                                 HttpServletRequest httpServletRequest) {
        String style =
                "^[a-zA-Z][a-zA-Z0-9._-]*@([a-zA-Z0-9-_]+\\.)+(com|gov|net|com\\.cn|edu\\.cn)$";
        Pattern ptt = Pattern.compile(style);
        Matcher mch=ptt.matcher(email);
        ActionErrors errors = new ActionErrors();
        if ((name == null || name.equals(""))) {
            ActionError error = new ActionError("error.name");
            errors.add("name", error);
        } else
        if (!mch.matches()) {
            ActionError error = new ActionError("error.email");
            errors.add("email", error);
        }
        return errors;
    }

只有注册用户登录后才能发表评论。


网站导航: