文本框仅允许Windows应用程序中的IP地址 [英] Text box only allow IP address in windows application

查看:62
本文介绍了文本框仅允许Windows应用程序中的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个仅允许使用IP地址的文本框.我可以在Web应用程序中创建此文件,但不能在Windows应用程序中创建此文件.请帮助我做到这一点.

I need a textbox that only allows an IP address. I can create this in a web application but i can't do this in windows application. Please help me to do this..

推荐答案

使用此方法来验证IP

Use this method to validate IP

 public bool IsValidIP(string addr)
    {
        //create our match pattern
        string pattern = @"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.
([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$";
        //create our Regular Expression object
        Regex check = new Regex(pattern);
        //boolean variable to hold the status
        bool valid = false;
        //check to make sure an ip address was provided
        if (addr == "")
        {
            //no address provided so return false
            valid = false;
        }
        else
        {
            //address provided so use the IsMatch Method
            //of the Regular Expression object
            valid = check.IsMatch(addr, 0);
        }
        //return the results
        return valid;
    }

这篇关于文本框仅允许Windows应用程序中的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆