In the code below, I need to know if the text held by the JTextField contains only characters or if it also contains numeric entries.
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);
}
You can use a loop to find any digits or any thing else other than characters.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.