繁体   English   中英

我怎么解决这个问题? : 至少允许一个数字字符没有正则表达式

[英]how can I solve this problem ? : At least one numeric character allowed without regex

if(password.search(/[0-9]/)){
    document.getElementById('fpasswords').innerHTML="*atleast one numeric character";
    return false;
}

在这里我使用了正则表达式,但我不想使用它,那么解决方案是什么?

您可以使用 function isNaN 检查每个字符,如果不是,则此 function 返回 false 和 true:

const str = 'Papayas1';

for (var i = 0; i < str.length; i++) {
  
  if(!isNaN(str.charAt(i))) console.log('this is a number')
  else console.log('this is not a number')
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM