I am in need to give validation on my EditText such that it allows me to enter a valid
ip address format ( ?.?.?.? ) ie example 132.0.25.225
or
web url format ( www.?.? ) ie example www.example.com
logic is that if user type any numeric value first then validation(IP) will do action
else user must write "www" before any web String
Note: it must perform onKeyListener() of EditText, i mean while user giving input
In short - I am not going to check when user completes input and press OK button
Any idea appreciated, Thanks.
should use java.net.InetAddress class. you can check for all formarts of IP address: host address (eg: 132.0.25.225) or host name (eg: www.google.com); IPv4 or IPv6 format is ok.
Source code should run on work thread, because sometime InetAddress.getAllByName(mStringHost) take long time. for example: you get address from host name.
Add a TextWatcher to your EditText and in the
Validate the input using a regex and if the input character doesn't match the regex, simply delete it using the following method.
This ione works perfectly for me for checking url in android
Here a different solution for an IP address validation but that could be used as reference also for a web url validation.
.........
}
ip
url
try this ..