jquery密码规则

发布于 2024-09-07 02:04:35 字数 393 浏览 3 评论 0原文

之前尝试过发布此内容,但它没有通过(我认为),所以如果这是重新发布,请忽略。然而,我昨天问了一个问题,并在这里的大力帮助下解决了这个问题。我有一个用户帐户页面,用户可以在其中编辑他们的帐户信息。现在,他们并不总是更改密码。因此,我仅在新密码框有输入时才需要当前密码框。我还应用了 equalTo: 以便我可以使用新密码框检查确认密码框。这就是全部工作。但是,现在我想对新密码框应用一些规则。例如密码必须至少有 6 个字符长,包含 1 个字母和 1 个数字,并且不能包含其他字符。有人可以指出我正确的方向吗?

这是我的最小长度的一些代码:

$(<%= NewPass1.GetName() %>").rules("add", {
  minlength: 6,
SOME REGEX HERE?

Tried posting this before but it did not go through (i think) so if this is a repost please disregard. However, I asked a question yesterday and figured it out with the wonderful help from here. I have a user account page where a user can edit their account information. Now, they don't always change their password. So, I made the Current Password box required only when the new password box had an input. I also applied equalTo: so that I can check the confirm password box with the new password box. That is all working. However, now I want to apply some rules to the new password box. Like the password has to be at least 6 chars long, contain one letter and one number, and not contain other characters. Can somebody please point me in the right direction?

here is some of the code I have for the min length:

$(<%= NewPass1.GetName() %>").rules("add", {
  minlength: 6,
SOME REGEX HERE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-09-14 02:04:35

试试这个功能。它检查密码是否为字母数字且长度至少为 6 个字符。它还检查它是否至少包含一位数字和一个字母。

function isValid(input)
{
     var reg = /^[^%\s]{6,}$/;
     var reg2 = /[a-zA-Z]/;
     var reg3 = /[0-9]/;
     return reg.test(input) && reg2.test(input) && reg3.test(input);
}

我假设您正在使用验证插件。要在插件中使用自定义方法,请尝试以下功能: http://docs .jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage

编辑:

编辑为允许除空格和“%”之外的所有字符。

Try this function. It checks that the password is alphanumeric and at least 6 characters long. It also checks that it contains at least one digit and one letter.

function isValid(input)
{
     var reg = /^[^%\s]{6,}$/;
     var reg2 = /[a-zA-Z]/;
     var reg3 = /[0-9]/;
     return reg.test(input) && reg2.test(input) && reg3.test(input);
}

I assume you are using the Validation plugin. To use a custom method with the plugin, try this function: http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage

EDIT:

Edited to allow all characters except spaces and '%'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文