• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Java Validation! Field should be Integer  RSS feed

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amit Indore
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}

}
}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!