public void validateForm(ActionRequest request, ActionResponse actionResponse) { String firstName = request.getParameter("firstName"); String lastName = request.getParameter("lastName"); String telephone = request.getParameter("phone"); String email = request.getParameter("email"); String comments= request.getParameter("comments"); StringBuilder errorMsg=new StringBuilder(); //StringBuffer errorMsg=new StringBuffer(); System.out.println(errorMsg.equals("")); System.out.println(errorMsg.length()); System.out.println("errrr="+errorMsg); String fname="[a-zA-z]+([ '-][a-zA-Z]+)*"; String lname="[a-zA-z]+([ '-][a-zA-Z]+)*"; String matchPhoneNumberPattern="[0-9]*"; String emailPattern="^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"; if (firstName == null ||firstName.equals("")) { errorMsg.append("Please Enter First Name "+"<br />"); } else if(!firstName.matches(fname)) { errorMsg.append("Please Enter First Namet "+"<br />"); } if(lastName == null ||lastName .isEmpty()) { errorMsg.append("Please Enter Last Name "+"<br />"); } else if(!lastName.matches(lname)) { errorMsg.append("Enter lastname in Name Format "+"<br />"); } if(telephone == null || telephone.isEmpty()) { errorMsg.append("Please Enter Telephone Number "+"<br />"); } else if(!telephone.matches(matchPhoneNumberPattern)) { errorMsg.append("Invalid Number please Enter valid number"+"<br />"); } if(email == null || email.isEmpty()) { errorMsg.append("Please Enter Email "+"<br />"); } else if(!email.matches(emailPattern)) { errorMsg.append("Invalid email id"+"<br />"); } if (comments == null || comments.equals("")) { errorMsg.append("You must Enter Comments "+"<br />"); } /*IN all cases this if block is executing,EVen though i enter all fields in proper format */ System.out.println(errorMsg.equals("")); if(!errorMsg.equals("")) { request.setAttribute("errorMsg", errorMsg); request.setAttribute("phone", telephone); request.setAttribute("email", email); System.out.println("If block..........!"); } else { String successMsg="Form Submited Successfully"; request.setAttribute("successMsg", successMsg); System.out.println("done..........!"); } }
if(errorMsg != String.Empty)
if(!errorMsg.equals(""))
if(errorList.size()>0){ }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)