美文网首页
JavaBean邮箱验证

JavaBean邮箱验证

作者: Jianbaozi | 来源:发表于2020-11-09 15:19 被阅读0次

Email class

package com.baozi;

import java.io.Serializable;

public class Email implements Serializable{
    private static final long serialVersionUID = 1L;
    private String mailAdd;
    private boolean email;
    public Email(){}
    public Email(String mailAdd){
        this.mailAdd=mailAdd;
    }
    public boolean IsEmail(){
        String Regex="\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
        if(mailAdd.matches(Regex))
            email=true;
        else
            email= false;   
    return email;
}
    public String getMailAdd() {
        return mailAdd;
    }
    public void setMailAdd(String mailAdd) {
        this.mailAdd = mailAdd;
    }
}

index.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312" isErrorPage="true"%>
<%request.setCharacterEncoding("gb2312"); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Email Check</title>
</head>
<body>
<form action="result.jsp" method="post">
<table align="center" width="300" border="1" height="150">
<tr>
<td colspan="2" align="center">
<b>邮箱检查</b>
</tr>
<tr>
<td align="right">邮箱地址:</td>
<td><input type="text" name="mailAdd"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit">
</td>
</tr>
</table>
</form>
</body>
</html>

result.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312"%>
<%request.setCharacterEncoding("gb2312"); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.baozi.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Show Result</title>
</head>
<body>
<%
String mailAdd=request.getParameter("mailAdd");
Email email=new Email(mailAdd);
if(email.IsEmail())
    out.println(mailAdd+"<br>是一个标准的Email地址");
else
    out.println(mailAdd+"<br>不是一个标准的Email地址");
%>
<a href="index.jsp">返回首页</a>
</body>
</html>

相关文章

网友评论

      本文标题:JavaBean邮箱验证

      本文链接:https://www.haomeiwen.com/subject/vbwlbktx.html