c# 随机生成电话号码

 ///

From:www.uzhanbao.com
        /// 随机生成电话号码
        ///

        ///
        public string getRandomTel()
        {
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            //aa = r.Next(a1, a2);  
            //foundMatch = Regex.IsMatch(strReturn, @"^(13[0-9]|147|15[0-9]|166|17[0-9]|18[0-9])\d{8}$");//正则匹配手机号码的格式
            string[] telStarts = "130,131,132,133,134,135,136,137,138,139,147,150,151,152,153,155,156,157,158,159,180,181,182,183,185,186,187,188,189,176,177,178,199,198,166".Split(',');
            int n = ran.Next(10, 1000);
            int index = ran.Next(0, telStarts.Length - 1);
            string first = telStarts[index];
            string second = (ran.Next(100, 888) + 10000).ToString().Substring(1);
            string thrid = (ran.Next(1, 9100) + 10000).ToString().Substring(1);
            return first + second + thrid;
        }

你可能感兴趣的:(C#)