Author Topic: Validate IP address  (Read 696 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Validate IP address
« on: October 20, 2015, 04:50:02 PM »
I want to validate the IP address entered into a textbox is a valid IPV4 format. ie 192.168.1.1.  Does anyone have a code sample that works?  I have googled this but my limited VB knowledge is quickly exceeded and I cant get anything to work, thanks. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Validate IP address
« Reply #1 on: October 20, 2015, 05:08:28 PM »
The trick to finding Google answers is to precede your search with ".NET", so I would search like this:

".net ip address parse"

But here is the answer you are looking for:
Code: [Select]
Dim IPAddress as System.Net.IPAddress
If NOT System.Net.IPAddress.TryParse(TextBox1.Text,IPAddress) then
    MsgBox "Invalid Address"
End If