File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Java Validation! Field should be Integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Java Validation! Field should be Integer" Watch "Java Validation! Field should be Integer" New topic
Author

Java Validation! Field should be Integer

Amit Indore
Ranch Hand

Joined: Jun 20, 2008
Posts: 31
Hi All,

I am receiving a value in int type java variable from jsp.I want to check it is int type or other.If it is not int value than it give error.
Exp for:
int pincode; // It should be integer ant it's length must be 6 digit.

Why can i check it is int or not and also length.

I do not want to use any Script.I am waning your reply........
Than's
Amit Jain
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Originally posted by Amit Indore:

Why can i check it is int or not and also length.

I do not want to use any Script.I am waning your reply........


Hi Amit,

Looks like these questions are contradicting. It seems you are using a web application and you want to validate the input what you get should be an integer value and having 6 digits.

If you don't prefer doing it via a client side scripting, you can always validate the value in the server side. But it involves a round-trip to the server and then back to the client in case of any error.

Does that help?


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Hi,

For validating whether the input value is of type int, I would usually wrap the int value into Integer object and work on that. Does this help?

Thanks
Ravi


Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Amit Indore
Ranch Hand

Joined: Jun 20, 2008
Posts: 31
Originally posted by Raghavan Muthu:


Hi Amit,

Looks like these questions are contradicting. It seems you are using a web application and you want to validate the input what you get should be an integer value and having 6 digits.

If you don't prefer doing it via a client side scripting, you can always validate the value in the server side. But it involves a round-trip to the server and then back to the client in case of any error.

Does that help?


Thank's Sir,

Actually i am using struts1.2 and i want to define server side integer validation. like field name: Pin code/Zip,mobile number.
Sir, how can i check whole value of int variable is number and how can i get
its length.
Amit Indore
Ranch Hand

Joined: Jun 20, 2008
Posts: 31
Originally posted by Schandha Ravi:
Hi,

For validating whether the input value is of type int, I would usually wrap the int value into Integer object and work on that. Does this help?

Thanks
Ravi


Thank's

I try it.
Sri Sudha
Greenhorn

Joined: Jun 07, 2011
Posts: 1
Please try this code for Integer validation

public class RegularExpression_Examples {


public static boolean validateNumber(String number) {
return number.matches("^\\d*$");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter Number: ");
String number = input.nextLine();
while (validateNumber(number) != true) {
System.out.print("Invalid PhoneNumber!");
System.out.println();
System.out.print("Enter Phone Number: ");
number = input.nextLine();
}

}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Validation! Field should be Integer