我有一个条件,我必须根据用户选择绕过特殊字符验证。 [英] I have a condition in which I have to bypass special character validation based on user choice.

查看:93
本文介绍了我有一个条件,我必须根据用户选择绕过特殊字符验证。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0
下来投票

最爱

问:我希望特殊字符验证取决于用户选择。我想在代码中添加一些基于特定条件的密码验证,特殊字符是否有效?下面。是我的推荐代码。你可以请求帮助,因为我急需这个功能:



函数checkPasswordValue(用户名,用户密码){

if(userpassword.length == 0){

返回请指定密码值!;

}

//规则1

如果(userpassword.length< 8){



if(document.getElementById(isOIS)!= null){



if(userpassword.length> 6){

返回密码太长 - 必须最多6个字符!;

}

}否则{

返回密码太短 - 必须至少8个字符!;

}



}

//规则2

if((userpassword.search(/ [AZ] / i)== -1)||

(userpassword.search(/ [\ W _] / i) == -1)||

(userpassword.search(/ [\ d] / i)== -1)){



返回密码必须包含至少一个字母字符和
+至少一个数字和特殊字符!;

}



我尝试了什么:



现在,我想要某些标志条件,以便我可以使用验证一个可选的方式取决于用户的选择。



不知何故这样:var noSpecialChar = true; if(!noSpecialChar){if((userpassword.search(/ [AZ] / i)!= 0)||(userpassword.search(/ [\ W _] / i)!= 0)||(userpassword.search (/ [\d] / i)!= 0)){return存在特殊字符; }}

0 down vote
favorite
Q: I want the special character validation is depend on user choice. I want to add something in the code that based on certain condition password validation for special character will work or not ? Below. is my code for refernce. Can you please help as i need that functionality urgent:

function checkPasswordValue(username, userpassword) {
if (userpassword.length == 0) {
return "Please specify Password value!";
}
// rule 1
if (userpassword.length < 8) {

if (document.getElementById("isOIS") != null ) {

if (userpassword.length > 6) {
return "Password too long - must be maximum 6 characters!";
}
}else{
return "Password too short - must be at least 8 characters!";
}

}
// rule 2
if ((userpassword.search(/[A-Z]/i) == -1) ||
(userpassword.search(/[\W_]/i) == -1) ||
(userpassword.search(/[\d]/i) == -1)) {

return "Password must contain at least one alphabetic character and "
+ "least one numeric and special character!";
}

What I have tried:

Now, I want certain flag condition so that I can use validation in an optional way depends on user's choice .

somehow like this :var noSpecialChar = true; if(!noSpecialChar){ if((userpassword.search(/[A-Z]/i) != 0) || (userpassword.search(/[\W_]/i) != 0) || (userpassword.search(/[\d]/i) != 0)) { return "Special Characters are present"; } }

推荐答案

Quote:

我希望我们可以使用一些标志类型来将此作为可选项。由于一些用户不想使用密码验证

用户正在从版本5升级到版本6.在版本5中,我们没有任何密码验证,但在6中必须进行密码验证。如果他想使用现有服务,那么他不想要密码验证,但如果他们在版本6中创建新服务,他们必须强制遵循密码验证规则。

I want we can use some flag type to make this as optional. As some users don't want to use password validation
Users are upgrading from version 5 to version 6. In version 5 we dont have any password validation but in 6 it is mandatory to have password validation. If he wants to work with existing service then he dont want password validation but if they are creating new service in version 6 they have to mandatorily follow password validation rule.





在表单中提供一个复选框,说明用户是想要使用现有服务还是新服务,根据复选框值可以启用/禁用验证。



Provide a checkbox in the form, stating that whether the user wants to use the existing service or new one, based on the checkbox value you can enable/disable the validation.

<input type="checkbox" id="chkUseExistingService" /> Use Existing Service ?




// rule 2
          var useExistingService = document.getElementById('chkUseExistingService').checked;
          if (!useExistingService) {
              if ((userpassword.search(/[A-Z]/i) == -1) || (userpassword.search(/[\W_]/i) == -1) || (userpassword.search(/[\d]/i) == -1)) {

                  return "Password must contain at least one alphabetic character and "
                  + "least one numeric and special character!";
              }
          }


这篇关于我有一个条件,我必须根据用户选择绕过特殊字符验证。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆