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,800
  • 1
  • 25
  • 27
0

You can user NumberUtils.isDigits from Apache

Apurv
  • 3,723
  • 3
  • 30
  • 51
0

Use regular expressions. [0-9]*

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
0

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

Thudani Hettimulla
  • 754
  • 1
  • 12
  • 32