0

Asp.Net/C#使用しています。パスワード フィールドを照合するために を使用RegularExpressionValidatorしています。私の要件は、少なくとも 7 文字の長さのパスワードを入力する必要があることです。パスワードには、アルファベットと数字の任意の組み合わせを含めることができますが、1 つだけを含める必要があります。英数字以外の文字、これをどのように達成できるかについて誰かが私に提案できますか. どんな提案でも大歓迎です.ありがとう

4

3 に答える 3

3

これを試して

String[] words = { "Foobaar", "Foobar1", "1234567", "123Fooo", "Fo12!", "Foo12!", "Foobar123!", "!Foobar123", "Foo#bar123" };

foreach (String s in words) {

    Match word = Regex.Match(s, @"
          ^                        # Match the start of the string
            (?=                    # positive look ahead
                [\p{L}\p{Nd}]*     # 0 or more letters or digits at the start
                [^\p{L}\p{Nd}]     # string contains exactly one non-digit, non-letter
                [\p{L}\p{Nd}]*     # 0 or more letters or digits after the special character 
            $)                     # till the end of the string
            .{7,}                  # match 7 or more characters
          $                        # Match the end of the string
        ", RegexOptions.IgnorePatternWhitespace);
    if (word.Success) {
        Console.WriteLine(s + ": valid");
    }
    else {
        Console.WriteLine(s + ": invalid");
    }
}
Console.ReadLine();

\p{L}プロパティ「文字」を持つユニコードコードポイントです

\p{Nd}プロパティ「数字」を持つユニコードコードポイントです

于 2012-04-23T06:32:15.920 に答える
1
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{7,20})


(           # Start of group
  (?=.*\d)      #   must contains one digit from 0-9
  (?=.*[a-z])       #   must contains one lowercase characters
  (?=.*[A-Z])       #   must contains one uppercase characters
  (?=.*[@#$%])      #   must contains one special symbols in the list "@#$%"
              .     #     match anything with previous condition checking
                {7,20}  #        length at least 7 characters and maximum of 20 
)

ここからコピペ。

于 2012-04-23T05:48:21.297 に答える
0

私は自分のニーズに合わせて以下を使用しました^([\w]*[(\W)]{1}[\d]*)$.

于 2012-04-23T06:32:21.617 に答える