Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java String & int  RSS feed

 
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
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!