简体   繁体   中英

How can i check the value of JFormattedTextField is what i need?

MaskFormatter mf = new MaskFormatter("(0###) ### - ## - ##"); // format
JFormattedTextField formattedTextField = new JFormattedTextField(mf);

With this code i get a phone number from user. For example "(0444) 111 - 12 - 34".

If user write nothing i get a string like this "(0 ) - - ".How can i check it if it is empty or not. And did the user write all numbers.

String text = formattedTextField.getText().toString();
Boolean flag1 = Character.isDigit(text.charAt(2));

if(flag1){
   System.out.println("NUMBER");
}else{
   System.out.println("NOT NUMBER");
}

I can check with this code.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM