至少一个数字和一个大写字母的javascript正则表达式 [英] javascript regular expression for atleast one number and one uppercase letter

查看:154
本文介绍了至少一个数字和一个大写字母的javascript正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查给定字符串是否包含至少一个数字和一个大写字母的正则表达式是什么? 预先感谢

what would be the regular expression to check if a given string contains atleast one number and one uppercase letter? Thanks in advance

我就是这样

function validate_pass{
var var_password = document.getElementById("npassword").value;
else if (!(/^(?=.*\d)(?=.*[A-Z]).+$/).test(var_password))){
    msg = "Password should contain atleast.";

    showErrorMsgPassword(msg);
    $('#npassword').val('');
    $('#cpassword').val('');
    return false;
  }

else return true;

推荐答案

自从我这样做已经有一段时间了,我可以肯定的是,有比这更有效的方法了.您将需要使用正向先行,但是应该有一种方法可以从其中删除通配符:

It's been a while since I've done this, and I'm fairly certain there is a more efficient way than this. You will need to use positive lookaheads, but there should be a way to remove the wildcards from within them:

此正则表达式(/^(?=.*[A-Z])(?=.*\d).*$/)如果符合条件,将返回整个密码.

This regex (/^(?=.*[A-Z])(?=.*\d).*$/) will return the entire password if it matches the criteria.

('a3sdasFf').match(/^(?=.*[A-Z])(?=.*\d).*$/);

这篇关于至少一个数字和一个大写字母的javascript正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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