Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   netbeans Q (http://www.go4expert.com/forums/netbeans-q-t28008/)

mariamMAB 13Mar2012 11:07

netbeans Q
 
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

mariamMAB 14Mar2012 17:08

Re: netbeans Q
 
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 14Mar2012 17:09

Re: netbeans Q
 
but please I need the solution for the other part which is E-mail validity check


All times are GMT +5.5. The time now is 19:07.