Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 查找字符串是否有数字_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 查找字符串是否有数字

Javascript 查找字符串是否有数字,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我目前正在伪造一个社交媒体网站。对于这个假网站,我试图建立一个注册表框,您的密码必须包含至少1个数字 例如:m4aster=true 但是:master=一个错误 我不在乎密码里有什么数字,只要有。我的代码是: var count = function hasNumbers(invulveld4) { return /\d/.test(invulveld4); } if(count = false){ $(".geencijfer").text("Voeg een cijfer aan

我目前正在伪造一个社交媒体网站。对于这个假网站,我试图建立一个注册表框,您的密码必须包含至少1个数字

例如:m4aster=true 但是:master=一个错误

我不在乎密码里有什么数字,只要有。我的代码是:

    var count = function hasNumbers(invulveld4)
{
return /\d/.test(invulveld4);
}
if(count = false){
$(".geencijfer").text("Voeg een cijfer aan uw wachtwoord toe.")
};

我希望你们都能帮助我

你的问题不是正则表达式。这是你的比较和你没有调用你的函数的事实

JavaScript中的比较是用两个或最好是三个等号进行的。 此外,使用布尔表达式,您可以跳过实际的比较,并像这样设置快捷方式

if(!hasNumbers(inputValue)) {
    $(".geencijfer").text("Voeg een cijfer aan uw wachtwoord toe.");
}
请尝试以下代码:

var count = function(mydigit){return /\d/.test(mydigit)}
count('master4')
if(count(yourvalue)==false) {
    $(".geencijfer").text("Voeg een cijfer aan uw wachtwoord toe.");
}
count将返回true或false。 在count'master'的情况下,count将返回false,因为找不到任何数字。 在count'master4'的情况下,count将在找到数字a后返回true

更新: 请尝试以下代码:

var count = function(mydigit){return /\d/.test(mydigit)}
count('master4')
if(count(yourvalue)==false) {
    $(".geencijfer").text("Voeg een cijfer aan uw wachtwoord toe.");
}

您实际上并没有调用您的函数;您键入了一个接受参数的函数,但没有向其传递任何内容。您还在if语句中使用=而不是==。请尝试在if中使用适当的运算符并调用您的函数