<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>RE</title>
</head>
<body>

    <p>
      使用正则表达式的方式来判断。
    </p>

<script>
function isValid(str) { return /^\w+$/.test(str); }
str = "1234abd__"
document.write(isValid(str));
document.write("<br>");

str2 = "$32343#"
document.write(isValid(str2));
document.write("<br>");
</script>

</body>
</html>

 

结果:

使用正则表达式的方式来判断。

true
false

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案