tags:

views:

85

answers:

2

Hi,

I'm totally new to Android.

I would like to put in a textbox where user can enter an IP address ... but how do I limit the user to only enter numbers? ... and how do I validate?

Is there a ready-made-ip-address-textbox "out there" I can use?

Thanks!

Mojo

A: 

What I've found that works is to set an EditText to use android:inputType="phone", so the input is restricted to digits, period, and a handful of other characters. However, this will only let you input IPV4 addresses, since it's digits only. For validation, you'll have to get the input text and parse it by hand.

As far as ready-made input widgets, I haven't come across one.

Erich Douglass
Great idea ... thanks!!!
MojoDK
A: 

For validation, regular-expressions.info has a good regex string you could use for testing for an IP in a valid (0-255) range:

\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

kcoppock
Yeah I was hoping for some kind of masked textbox, but regex is a good solution - thanks!
MojoDK
Yeah, you could probably extend a custom textbox, but I wouldn't even know where to start with that. Good luck!
kcoppock