0

I was wondering if there was a way to validate in my app so text entered into a "Phone Number" section can only add numeric characters and adds a System.out.println if the user attempts to enter Alphabetical/Special characters. I've uploaded my code here: http://pastebin.com/jZ7Xgiq9 Since I'm not too sure how I'd implament it.

I was also wondering if there was a way to disable spaces being added?

RoboVisits
  • 35
  • 9

4 Answers4

1

Check out Googles lib for parsing phonenumbers, it's really neat!

jontejj
  • 2,670
  • 1
  • 23
  • 27
0

You can user NumberUtils.isDigits from Apache

Apurv
  • 3,675
  • 3
  • 29
  • 49
0

Use regular expressions. [0-9]*

Adam Stelmaszczyk
  • 19,333
  • 4
  • 67
  • 107
0

Add a KeyListener to txtPhone and use, txtPhone.getText().matches("[0-9]*"); at keyTyped() event.

Thudani Hettimulla
  • 726
  • 11
  • 31