簡體   English   中英

如何檢查TextField是否僅包含字符

[英]How to check if the TextField contains only characters

在下面的代碼中,我需要知道JTextField所保存的文本是否僅包含字符或是否還包含數字條目。

ResultSet rs= ItemQuery.findItem(jTextfield1.getText());
while(rs.next()){
    i_name =rs.getString(2);
    jLabel5.setText(i_name);
    currStock = Integer.toString(rs.getInt(3));
    jLabel6.setText(currStock);
    date = new SimpleDateFormat("yyyy-MM-dd").format(rs.getDate(4));                
    jLabel8.setText(date);
}

您可以使用循環查找字符以外的任何數字或其他任何東西。

flag=1;
for (int i=0;i++;i<string.size()){
   if (!Character.isLetter(string.charat(i))){
        flag=0;
        break;
   }
}

 if (flag==0)
  // control enters this if statement when any thing other than letters is encountered in the string

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM