我必须对文本框中的文本进行一些模式匹配。我在C#中的服务器回发事件中正在执行此操作。
我的正则表达式如下:

 public bool ValidatePassword(string temp)
    {
        bool isMatch = false;
        passwd = passwd.Trim();

        isMatch = Regex.IsMatch(temp,
                             @"^           # Start of string
                        (?=.*\p{Lu})      # Assert at least one uppercase letter
                        (?=.*\p{Ll})      # Assert at least one lowercase letter
                        (?=.*\d)          # Assert at least one digit
                        (?=.*[^\p{L}\d])  # Assert at least one other character
                        .{8,13}           # Match at least 8 characters and maximum of 13 characters
                        $                 # End of string",
                             RegexOptions.IgnorePatternWhitespace);


        return isMatch;
    }


我想将其移至Javascript,以便在客户端进行匹配。有人可以帮我将此功能移至Javascript吗?

最佳答案

就像是:

function ValidatePassword(temp) {
  return /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[^a-zA-Z\d]).{8,13}$/.test(temp);
}

08-04 02:59