Email field validation JSP for Access Request forms
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Following is the contents of the field validation jsp for validating if a text field for email address has it in the right format:
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
try {
String name = request.getParameter("name");
String question = request.getParameter("question");
String value = request.getParameter("value");
Pattern pattern = Pattern.compile("^.+@.+\\..+$");
Matcher matcher = pattern.matcher(value);
if (!matcher.matches())
out.println("Invalid User Id for " + question + ", expected ####@####.###");
}
catch (IOException e) {
e.printStackTrace();
}
%>
For details on field and form validation jsps, refer here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.