Android judge IP address legal implementation code

Android judge IP address legal implementation code

Yesterday, I searched the Internet to judge whether the string in the text box is a legal IP address. I thought of a regular expression, but I am not familiar with it, so I found some information on the Internet and finally made it.

The specific code is very simple,

This code first uses the regular expression to judge whether it is legal. In fact, it is to judge whether the right three dots separate the string. However, it does not judge whether the string is a number. Therefore, later, I found another code to judge IP. If the previous judgment is legal, I will separate the character string with dots, and then force it into a number to judge whether it is between 0 and 255, If it is not satisfied or an error is reported, the string is returned, which is not a false variable of IP.

This completes the judgment of IP legitimacy.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>