Q: how to validate textbox input as a digit in netbeans my problem is how to validate  textbox input as a digit and the textbox shouldn't  be empty.
i need to check these 2 at once code segment
//i code for not emty 
if(jTextField1.getText())

A: try this and that was having some thing wrong pattern.
try {
            String regex = "[0-9]+";
            String data = jTextField1.getText();
            System.out.println(data.matches(regex));


            if (!data.matches(regex)) {
                JOptionPane.showMessageDialog(this, "Please Enter Digites");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }


A: I often use try/NumberFormatException, to make sure the result is valid:
(I suppose you fill an object's field with the value the user entered into the textbox)
For example:
try {mobjSomeObject.setSomeProp(Integer.parseInt(txtTextBox.getText()));} 
  catch (NumberFormatException nFE) {... do something if not a number ...;}
