C#中如何获取任意字母组合和验证邮件格式

    //产生随机任意字母长度组合
    public string RndNum1(int VcodeNum)
    {
        string Vchar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string VNum = "";
        Random rand = new Random();
        for (int i = 0; i < VcodeNum; i++)
        {
            VNum += Vchar[rand.Next(Vchar.Length - 1)].ToString();
        }
        return VNum;

    }

    //返回:A46U-2VD4 形式的任意字母组合
    public string RndNum2(int VcodeNum)
    {
        string Vchar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string VNum = "";
        Random rand = new Random();
        for (int i = 1; i <= VcodeNum; i++)
        {
            if (i % 8 == 0 && i != VcodeNum)
            {
                VNum += Vchar[rand.Next(Vchar.Length - 1)].ToString() + "-";
            }
            else
            {
                VNum += Vchar[rand.Next(Vchar.Length - 1)].ToString();
            }
        }
        return VNum;

    }

 //邮件格式是否正确
    public static bool isEmail(string inputEmail)
    {
        string strRegex = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
        Regex re = new Regex(strRegex);
        if (re.IsMatch(inputEmail))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

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