• 字母,数字,正则


    //生成数字加字母的字符串的方法
        public static string ToRandPwd()
        {
            Random random = new Random();
            int pwdLength = random.Next(6, 10);//密码长度控制在6到10位之间
            string password = "";
            string temp1 = string.Empty;
            int digitNum1 = random.Next(pwdLength - 1);
            if (digitNum1 == 0)
            {
                digitNum1 = 1;
            }
            int charUpperNum1 = random.Next(pwdLength - digitNum1);
            if (charUpperNum1 == 0)
                charUpperNum1 = 1;
            int charLowerNum1 = pwdLength - digitNum1 - charUpperNum1;

            for (int i = 0; i < digitNum1; i++)
            {
                temp1 += random.Next(0, 10);//digit
            }
            for (int i = 0; i < charUpperNum1; i++)
            {
                temp1 += (char)random.Next(65, 91);//upper case
            }
            for (int i = 0; i < charLowerNum1; i++)
            {
                temp1 += (char)random.Next(97, 123);
            }

            for (int i = 0; i < pwdLength; i++) //disarrange password
            {
                int n = random.Next(temp1.Length);
                password += temp1[n];
                temp1 = temp1.Remove(n, 1);
            }

            return password;
        }

    using System.Text.RegularExpressions;

    if(Regex.IsMatch(this.TextBox1.Text,@"^(?!([^A-Za-z]|\d)+$)[a-zA-Z\d]{6,}$")) //@"^(?!\D+$)(?![^a-z]+$)[a-zA-Z\d]{6,}$"
            {
                Response.Write("你输入的符合是至少为六位且必须是数字和字母组合的字符串");
            }

    if (Regex.IsMatch(this.TextBox1.Text, @"^[A-Za-z]+$"))
            {
                Response.Write("都是字母");
            }

  • 相关阅读:
    select选择框去掉默认的下拉箭头
    网站怎么添加ico小图标
    js实现逐字打印效果,文本逐字显示
    jQuery实现消息列表循环垂直向上滚动
    滤镜图片变黑白+图片模糊
    多选下拉框(select 下拉多选)
    JavaScript 数组相关基础方法
    h5+ IOS App中判断本地文件是否存在 plus.io.resolveLocalFileSystemURL()
    h5+ IOS App中取消视频默认全屏播放
    C# 多线程与队列操作小练刀
  • 原文地址:https://www.cnblogs.com/blncle/p/2538354.html
Copyright © 2020-2023  润新知