Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java String & int

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to validate form with Java Servlet.

How can I check in Java that user is giving me String or int??

Thanks & best regards
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All form fields come in as either java.lang.String (or String[] with getParameterValues).

To insure that a field is numeric, you can either create a regular expression and match it against that or try to convert it to an int with Integer.parseInt from with a try/catch block.
[ March 27, 2008: Message edited by: Ben Souther ]
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
All form fields come in as either java.lang.String (or String[] with getParameterValues).

To insure that a field is numeric, you can either create a regular expression and match it against that or try to convert it to an int with Integer.parseInt from with a try/catch block.

[ March 27, 2008: Message edited by: Ben Souther ]


Can you please get me any regex example?
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic