![](/img/trans.png)
[英]How to validate a column in a jtable that can accepts only mobile numbers?
[英]How to validate an empty textField that can accepts only integers?
我這樣寫的; 但它不能僅整數文本字段
if(textField_1.getText().length()==0)
JOptionPane.showMessageDialog(null, "enter text in textfield");
請幫忙...
if(textField_1.getText().isEmpty()){
JOptionPane.showMessageDialog(null, "enter text in textfield");
}
通常,在使用Java驗證用戶輸入時,您需要檢查空字符串值和空字符串值。 要檢查String對象是否相等,必須使用.equals()方法(而不是==運算符)。 因此,檢查空String值可能如下所示:
if ( val == null || val.trim().equals( "" ) )
{
// handle empty String case
}
else
{
// handle non-empty String case
}
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.