Sub Activity_Create(FirstTime As Boolean)
Log(IsValidIp("192.168.1.83"))
Log(IsValidIp("192.168.2221.83"))
End Sub
Sub IsValidIp(ip As String) As Boolean
Dim m As Matcher
m = Regex.Matcher("^(\d+)\.(\d+)\.(\d+)\.(\d+)$", ip)
If m.Find = False Then Return False
For i = 1 To 4
If m.Group(i) > 255 OR m.Group(i) < 0 Then Return False
Next
Return True
End Sub
(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])
This doesn't mean that there is any advantage with doing it with regex. Regex is a tool not a purpose.Also, it is possible to do the "< 256" check in the regex.
B4X:(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])