VB6利用正则表达式验证IP地址合法性
‘------IP 地址
Public Function isValidIpAddress(strIpAddress As String) As Boolean Dim reg As New RegExp, i As Integer reg.IgnoreCase = True reg.Global = True reg.MultiLine = True reg.Pattern = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" isValidIpAddress = reg.Test(strIpAddress) If isValidIpAddress = True Then Dim strArr() As String strArr = Split(strIpAddress, ".") For i = 0 To UBound(strArr) isValidIpAddress = isValidIpAddress And isValidIpNumber(strArr(i)) Next i End If End Function Private Function isValidIpNumber(strNumber As String) Dim ipnum As Integer ipnum = CInt(strNumber) isValidIpNumber = (ipnum < 256) End Function