您的位置:首页 > 编程语言 > C#

C#验证字符串是否是数字、传真、邮政编码、网址或者电子邮件

2015-07-24 10:33 351 查看
        #region  验证数字

        public static bool strIsNum(string str)

        {

            return Regex.IsMatch(str, "^[0-9]*$");

        }

        #endregion

        #region  验证传真

        public static bool strIsFax(string str)

        {

            return Regex.IsMatch(str, @"86-\d{3,4}-\d{7,8}");

        }

        #endregion

        #region  验证邮政编码

        public static bool strIsPostCode(string str)

        {

            return Regex.IsMatch(str, @"\d{6}");

        }

        #endregion

        #region  验证电子邮件

        public static bool strIsEmail(string str)

        {

            return Regex.IsMatch(str, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

        }

        #endregion

        #region  验证网址

        public static bool strIsNAddress(string str)

        {

            return Regex.IsMatch(str, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");

        }

        #endregion
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# 字符串