Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

need US state validation



Client does not want STATe dropdown. Please provide a validation using JSP, Struts or Java

Please DON'T point me to a piece of documentation.  I need specifics  since I'm new to the web world

This is my 3rd request for this in Experts exchange --- very frustrating web site
0
VKopacz
Asked:
VKopacz
  • 2
1 Solution
 
arnon81Commented:
//form.jsp-----------
<%
if (request.getParameter("err")!=null)
      out.println ("Please correct state name");
%>
<br>
<form method='post' action='action.jsp'>
<input type=text name='state'/>
<input type=submit value=submit/>
</form>





//action.jsp-----------

<%
String[] states = {"IA", "CA", "MO"}; //add more state as you wish....
String inputstate = request.getParameter("state");

boolean found=false;
for (int i=0; i<states.length; i++)
{
      if (states[i].equals(inputstate))
            found=true;
}
if (!found)
      response.sendRedirect ("form.jsp?err=1");
else
      response.sendRedirect ("thankyou.jsp");
%>






//thankyou.jsp-----------
Thank you !!





0
 
arnon81Commented:
oh and on form.jsp
might be better to use
<input type=text name='state' maxlength='2'/>
instead of
<input type=text name='state'/>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now