2015-10-20 76 views
0

驗證一個整數值,如何通過形式在Java通過形式

if(!(Integer.parseInt(txtStart.getText()).equals(txtStart.getText())) 
{ 
    JOptionPane.showMessageDialog(null, "Please Enter Valid Start Page"); 
} 

回答

0

驗證一個整數值,隨着下一個代碼,你可以驗證你的文字是一個數字。

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; 
    } 

} 

輸出

txtValue1: false 
txtValue2: false 
txtValue3: true 
+0

非常感謝你可租可買它幫助我 –

+0

請不要忘記額定問題 –