Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Validate the Integers doesnot allow the string values using java

 
Kumar Naidu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

i have one bean that bean contains string and integer values setter and getter method i am writen the validations integer variables and string variables sucessfully. but i am entered the values in jsp form integer place string values entered that time 500 error is retrived. how to write the Integer text boxes allow the strings the time does not fire the 500 error. only Retrive the Error messageas. i am using Pattern and matcher classes.

Regards
Vinay
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...but i am entered the values in jsp form integer place string values entered that time 500 error is retrived.


It looks from your post that textfield require integer and if user enters String, 500 internal server errors at the server side.

From the textfield, the retrieved value will always be a string. You can use valueOf(String) method for validation. It returns you an Integer object. If it fails, you will get a NumberFormatException.


By parsing, you can filter illegal entered values.

Is this you are looking for?


- Naseem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic