java - Testing whether an input is a number -


i have program, whenever type , hit enter, prints out in window (it's command prompt). however, due few problems calculator function i'm trying add, if user input number, want totally ignore

    input = new jtextfield();     input.seteditable(true);     input.setforeground(color.white);     input.setcaretcolor(color.white);     input.setopaque(false);      input.addactionlistener(new actionlistener(){          public void actionperformed(actionevent e) {              string text = input.gettext();              if (text.length() >= 1){                  print(text + "\n", false);                  docommand(text);                 scrollbottom();                 input.selectall();             }          }     }); 

you check if text number regex that:

text.matches("[1-9][0-9]*"); 

i hope helps.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -