Android Question Validate IP Number

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
Helo,

with the below Code, I try to validate an IP number.
But I get an Error msg.

B4X:
Sub Validate_IPNUmmer(IP_Adresse As String) As Boolean
    Dim Match_IP As Matcher = Regex.Matcher("^(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}$",IP_Adresse)
    If Match_IP.Find = True Then
        ToastMessageShow("IS IP ",True)
        Return True
        Else
            ToastMessageShow("Is not IP", True)
            Return False
    End If
End Sub
 

thetahsk

Active Member
Licensed User
Longtime User
Helo,

with the below Code, I try to validate an IP number.
But I get an Error msg.

B4X:
Sub Validate_IPNUmmer(IP_Adresse As String) As Boolean
    Dim Match_IP As Matcher = Regex.Matcher("^(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}$",IP_Adresse)
    If Match_IP.Find = True Then
        ToastMessageShow("IS IP ",True)
        Return True
        Else
            ToastMessageShow("Is not IP", True)
            Return False
    End If
End Sub
B4X:
'Tests given string if it looks like an ipv4 address
Public Sub IsValidIPv4Address(IPAddress As String) As Boolean
    Return Regex.IsMatch("^(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])$", IPAddress)   
End Sub

'Tests given string if it looks like an ipv6 address
Public Sub IsValidIPv6Address(IPAddress As String) As Boolean
    Return Regex.IsMatch("^([0-9a-f]{1,4}:){7}([0-9a-f]){1,4}$", IPAddress)
End Sub

see https://www.b4x.com/android/forum/threads/ip-address-validation-using-regex.72789/
 
Upvote 0
Top