How to validate an integer value through form in java
if(!(Integer.parseInt(txtStart.getText()).equals(txtStart.getText()))
{
JOptionPane.showMessageDialog(null, "Please Enter Valid Start Page");
}
How to validate an integer value through form in java
if(!(Integer.parseInt(txtStart.getText()).equals(txtStart.getText()))
{
JOptionPane.showMessageDialog(null, "Please Enter Valid Start Page");
}
With the next code you can validate is your text is a number.
public class Main {
public static void main(String args[]){
String txtValue1 = "";
String txtValue2 = "a";
String txtValue3 = "3";
System.out.println("txtValue1: "+isNumber(txtValue1));
System.out.println("txtValue2: "+isNumber(txtValue2));
System.out.println("txtValue3: "+isNumber(txtValue3));
}
private static boolean isNumber(String _value){
boolean result = true;
try{
Double.parseDouble(_value);
}catch(Exception e){
result = false;
}
return result;
}
}
Output
txtValue1: false
txtValue2: false
txtValue3: true