IP Address in a MaskedTextBox?

前端 未结 6 1543
無奈伤痛
無奈伤痛 2020-12-03 15:09

How can I use a MaskedTextBox to prevent the user from entering an invalid IP address? (I want it to behave just like the Windows one).

6条回答
  •  醉话见心
    2020-12-03 15:23

    Try this:

    IPAddress ipAddress;
    if (IPAddress.TryParse(maskedTextBoxY.Text, out ipAddress))
    {
        //valid ip
     }
    else
     {
        //is not valid ip
    }
    

    note: to use it, you need import the System.Net namespace:

    using System.Net;
    

提交回复
热议问题