1
0
-1
2 answers
- 10-1
Hi, it is impossible for a primitive type like int to be null or empty. You can try to initialize a variable with -1 (to indicate negative value) and assign Integer.parseInt(values[0]) to it, then check if it's still equal to -1 after the assignment.
Try to refer to this: https://stackoverflow.com/questions/13747859/how-to-check-if-an-int-is-a-null
Add your comment... - 10-1
Hi, the problem is that after converting the value into an integer, you are comparing it to an empty string. You need to perform comparison using the same types.
Integer.parseInt(values[0]) == ""
Hi, i wan to use bean shell validator for must fill and range value. But for must fill value is not working. Here is my script:
if(Integer.parseInt(values[0]) == ""){
formData.addFormError("total_value", "Please fill the value"); //not working
return false;
}else if(Integer.parseInt(values[0]) < 3000){
formData.addFormError("total_value", "Value must between 30001-4000."); //working
return false;
}else if(Integer.parseInt(values[0]) > 4000){
formData.addFormError("total_value", "Value must between 30001-4000."); //working
return false;
}
else{
return true;
}