cancel
Showing results for 
Search instead for 
Did you mean: 

Integer Validation Simple Type

Former Member
0 Kudos

Hi to all

we have requirement that the value entered should be with in the range 0 to 9999

For this in webdynpro for java i tried to create a simple type of integer with minimum inclusive as 0 and maximum inclusive as 9999

but if we give say 99999 it gives valid message -- Value 99999 must be smaller than MaxExclusive 9999

if we give 23423423423423423423 it gives the java message integer range should be with in this range -2147483648 and +21...)

if we give decimal values it gives the same java message integer range should be with in this range

2147483648 and +21...)

For me

i should always be able to get this message Value 99999 must be smaller than MaxExclusive 9999 or

Value -1 must be greater than or the same as Minclusive 0

irrespective of the input

is there any way that i can have this kind of message

to conclude what ever the input i give it should give me message value should be with in the range 0 to 9999

could some one please help in this tricky requirement

Thanks in advance

Regards

Chandra

Accepted Solutions (0)

Answers (1)

Answers (1)

nitin_mahajan2
Contributor
0 Kudos

You Should use the java forum for such issues. Nevertheless,

The error that you described is standard, the one you are asking is custom. You will have to create custom code

Make a Long value out of the Integer value.

After reading, physically check for range of 0 - 9999

Show the message as required using



int value = //read value from the UI
 
String str = String.valueOf( value );
 
 long abc =  Long.parseLong( str );
 

if(abc<= 0 || abc >= 9999 ) {  

//error message

}



Regards,

Nitin

Edited by: Nitin Mahajan on Jun 17, 2009 11:45 PM

Former Member
0 Kudos

Hi Nitin,

Thanks for your reply.

I was looking for some Options in webdynpro so that i can have these input validations,

i have tried what you have told, its fine but one of the cases result in the following error

suppose if the user gives 1.1 as input it again gives two error message one which is custom message and the other is standard message

Give 1.1 when we press enter

we result in two messages..

1. Value must be of type integer (between -2147483648 and 21...)

2. Quanity should be between 0 to 9999.

We should not get this standard error message at any case.

Thanks in advance

Regards

Chandra

Former Member
0 Kudos

Hi,

You can check with this code wether it is numeric or not


public boolean isNumeric(int K) {

   String s = String.valueOf(k);
   
   char[] numbers = s.toCharArray();
   
	 for (int i = 0; i < numbers.length; i++) {
		if (!('.'==numbers<i>)&& !Character.isDigit(numbers<i>)) 
		return false;
	 }
	 return true;
  }

if(isNumeric()==false)
{
   error message;
}

Hope this helps you in resolving the problem

Regards,

Saleem

nitin_mahajan2
Contributor
0 Kudos

Saleem, the user is entering a numeric value, question is which data type it is, int/float/long/double

Chandra,

Value 1.1 is not an integer value or a long value. The data type is float.

when you converted it in a string, look for the indexof(.), and check the value of string after (.), it should not be greater than 0. If it is, the entered number is not an integer.

so it goes like this



string a = substring( string after " ." ) ;

int i = int value of a ;

if ( i > 0 ) "please enter an integer value " ;
else{ conver to lang and do remaining process }

Regards,

Nitin

Edited by: Nitin Mahajan on Jun 19, 2009 12:16 AM