netbeans Q

mariamMAB's Avatar, Join Date: Feb 2012
Go4Expert Member
Hi,
This is my index.jsp page
HTML Code:
<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

Last edited by shabbir; 13Mar2012 at 11:26.. Reason: Code blocks
mariamMAB's Avatar, Join Date: Feb 2012
Go4Expert Member
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 Code:
protected void processRequest(HttpServletRequest requestHttpServletResponse response)
            
throws ServletExceptionIOException {
        
response.setContentType("text/html;charset=UTF-8");
        
PrintWriter out response.getWriter();
        
         
String uPhone request.getParameter("uPhone");
         
String uEmailrequest.getParameter("uEmail");
        
        
       
        
char[] chars = new char[uPhone.length()];
        
uPhone.getChars(0chars.lengthchars0);
        for (
int i 0chars.lengthi++) {
          if (!(
'0' <= chars[i] && chars[i] <= '9')) {
            
RequestDispatcher dispatcher =
            
getServletContext().getRequestDispatcher("/Wrong.jsp");
            
dispatcher.forward(requestresponse);
            
          }
          
        }
        
RequestDispatcher dispatcher =
            
getServletContext().getRequestDispatcher("/Correct.jsp");
            
dispatcher.forward(requestresponse);
             
    } 
mariamMAB's Avatar, Join Date: Feb 2012
Go4Expert Member
but please I need the solution for the other part which is E-mail validity check