Hi, This is my index.jsp page HTML: <body> <h1>Login: </h1> <form name="myForm" action="getPassword" method="POST"> Name <input type="text" name="uName" value="" /><br /> Password: <input type="password" name="uPass" value="" /><br /> Address <input type="text" name="uAddress" value="" /><br /> Phone <input type="text" name="uPhone" value="" /><br /> Email <input type="text" name="uEmail" value="" /><br /> <input type="submit" name="btSubmit" value="Send" /> </form> </body> >>>>>and this is my servlet <<<<< Code: protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String uPhone = request.getParameter("uPhone"); String uEmail= request.getParameter("uEmail"); if(uPhone ?????????){ RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Correct.jsp"); dispatcher.forward(request, response); return; }else{ RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Wrong.jsp"); dispatcher.forward(request, response); return; } >>> I want to A Servlet that: - checks the phone number has only numbers and no characters - checks if the email address has '@' (at) symbol and a '.' (dot) in it What should I wrote in ???? place
Oh lazy people I already found the answer for the first part which is the phone, I will write it just in case someone will use it: PHP: protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String uPhone = request.getParameter("uPhone"); String uEmail= request.getParameter("uEmail"); char[] chars = new char[uPhone.length()]; uPhone.getChars(0, chars.length, chars, 0); for (int i = 0; i < chars.length; i++) { if (!('0' <= chars[i] && chars[i] <= '9')) { RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Wrong.jsp"); dispatcher.forward(request, response); } } RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Correct.jsp"); dispatcher.forward(request, response); }