{"id":155184,"date":"2024-05-08T11:48:00","date_gmt":"2024-05-08T03:48:00","guid":{"rendered":""},"modified":"2024-05-08T11:48:04","modified_gmt":"2024-05-08T03:48:04","slug":"%e7%a7%bb%e5%8a%a8%e7%ab%af%e9%a1%b9%e7%9b%ae%e5%bc%80%e5%8f%91%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8-js-%e6%ad%a3%e5%88%99%e5%8c%b9%e9%85%8d%e6%95%b4%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/155184.html","title":{"rendered":"\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u600e\u4e48\u4f7f\u7528 js \u6b63\u5219\u5339\u914d\u6574\u6570"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26213600\/2038c7d5-782e-4695-82e5-3070c5369153.webp\" alt=\"\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u600e\u4e48\u4f7f\u7528 js \u6b63\u5219\u5339\u914d\u6574\u6570\" \/><\/p>\n<p><p>\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4f7f\u7528JavaScript\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6574\u6570\u5339\u914d\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u6a21\u5f0f\u5b9e\u73b0\uff0c<strong>\u5177\u4f53\u5305\u62ec\uff1a\u7f16\u5199\u4e00\u4e2a\u5339\u914d\u6b63\u6574\u6570\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u521b\u5efa\u4e00\u4e2a\u80fd\u591f\u8bc6\u522b\u8d1f\u6574\u6570\u7684\u6a21\u5f0f\u3001\u4ee5\u53ca\u5f00\u53d1\u4e00\u4e2a\u8bc6\u522b\u6b63\u8d1f\u6574\u6570\u548c\u96f6\u7684\u7efc\u5408\u8868\u8fbe\u5f0f<\/strong>\u3002\u5bf9\u4e8e\u5339\u914d\u6574\u4e2a\u6574\u6570\uff0c\u4e00\u4e2a\u57fa\u672c\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\uff1a<code>\/^-?\\d+$\/<\/code>\u3002\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u6838\u5fc3\u5728\u4e8e<code>-?<\/code>\u8868\u793a\u8d1f\u53f7\u662f\u53ef\u9009\u7684\uff0c<code>\\d+<\/code>\u8868\u793a\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u5b57\uff0c<code>^<\/code>\u548c<code>$<\/code>\u5206\u522b\u8868\u793a\u884c\u7684\u5f00\u59cb\u548c\u7ed3\u675f\uff0c\u786e\u4fdd\u6574\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u4e00\u4e2a\u6574\u6570\u3002<\/p>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u5de5\u4f5c\u5728\u5b57\u7b26\u4e32\u4e0a\u6267\u884c\u6a21\u5f0f\u5339\u914d\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u5728\u5904\u7406\u7528\u6237\u8f93\u5165\u3001\u6570\u636e\u9a8c\u8bc1\u7b49\u60c5\u5f62\u4e0b\u5f97\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u7ed3\u5408\u79fb\u52a8\u7aef\u9879\u76ee\u5bf9\u6027\u80fd\u7684\u8981\u6c42\u548c\u7528\u6237\u4ea4\u4e92\u7684\u5373\u65f6\u6027\uff0c\u5408\u7406\u5730\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<\/p>\n<p><h3><strong>\u4e00\u3001\u7b80\u4ecb<\/strong><\/h3>\n<\/p>\n<p><p><strong>JavaScript\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5b57\u7b26\u5339\u914d\u5de5\u5177\uff0c\u5b83\u5141\u8bb8\u4f60\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u6a21\u5f0f\u3002\u5728\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u9a8c\u8bc1\u7528\u6237\u7684\u8f93\u5165\uff0c\u6bd4\u5982\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u6574\u6570\u3002\u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u7cbe\u786e\u5730\u5339\u914d\u548c\u6821\u9a8c\u6574\u6570\u3002<\/p>\n<\/p>\n<p><h3><strong>\u4e8c\u3001\u57fa\u7840\u5339\u914d\u6b63\u6574\u6570<\/strong><\/h3>\n<\/p>\n<p><p>\u8981\u5339\u914d\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">\/^\\d+$\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u53ef\u4ee5\u89e3\u8bfb\u4e3a\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>^<\/code> \u8868\u793a\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u3002<\/li>\n<li><code>\\d+<\/code> \u8868\u793a\u4e00\u4f4d\u6216\u591a\u4f4d\u6570\u5b57\uff0c<code>\\d<\/code>\u662f\u6570\u5b57\u7684\u7b80\u5199\u5f62\u5f0f\uff0c<code>+<\/code>\u8868\u793a\u5339\u914d\u4e00\u4e2a\u6216\u591a\u4e2a\u524d\u9762\u7684\u5b57\u7b26\u3002<\/li>\n<li><code>$<\/code> \u8868\u793a\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\u3002<\/li>\n<\/ul>\n<p><p><strong>\u4f7f\u7528\u8fd9\u79cd\u6a21\u5f0f\uff0c\u4f60\u53ef\u4ee5\u786e\u4fdd\u7528\u6237\u8f93\u5165\u7684\u662f\u6ca1\u6709\u524d\u5bfc\u96f6\u7684\u6b63\u6574\u6570\u3002<\/strong><\/p>\n<\/p>\n<p><h3><strong>\u4e09\u3001\u5339\u914d\u6b63\u6574\u6570\u548c\u96f6<\/strong><\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u5e94\u7528\u573a\u666f\u9700\u8981\u5c06\u96f6\u5305\u542b\u5728\u5339\u914d\u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u7a0d\u4f5c\u8c03\u6574\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">\/^(0|[1-9]\\d*)$\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u6539\u53d8\u5728\u4e8e\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>0|[1-9]\\d*<\/code> \u8868\u793a\u5339\u914d\u5355\u4e2a\u96f6\u6216\u8005\u4e00\u4e2a\u975e\u96f6\u5f00\u5934\u7684\u6570\u5b57\u5e8f\u5217\u3002<\/li>\n<\/ul>\n<p><p><strong>\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u6269\u5c55\u4e86\u5339\u914d\u6a21\u5f0f\uff0c\u63a5\u53d7\u6570\u5b57\u96f6\u4f5c\u4e3a\u5408\u6cd5\u8f93\u5165\u3002<\/strong><\/p>\n<\/p>\n<p><h3><strong>\u56db\u3001\u5339\u914d\u8d1f\u6574\u6570<\/strong><\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u8fd8\u9700\u8981\u5339\u914d\u8d1f\u6574\u6570\u3002\u6b64\u65f6\uff0c\u4f60\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u9700\u8981\u8fdb\u4e00\u6b65\u6269\u5c55\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">\/^-[1-9]\\d*$\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u4e2d\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>^-<\/code> \u8868\u793a\u4e00\u4e2a\u5fc5\u987b\u6709\u7684\u8d1f\u53f7\u5728\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u3002<\/li>\n<li><code>[1-9]\\d*<\/code> \u8868\u793a\u4e00\u4e2a\u975e\u96f6\u6570\u5b57\u5f00\u59cb\uff0c\u540e\u9762\u8ddf\u968f\u4efb\u610f\u4e2a\u6570\u5b57\u3002<\/li>\n<\/ul>\n<p><p><strong>\u6b64\u6a21\u5f0f\u786e\u4fdd\u4e86\u8d1f\u6574\u6570\u4e0d\u4f1a\u6709\u524d\u5bfc\u96f6\uff0c\u5e76\u4e14\u662f\u4e00\u4e2a\u5408\u7406\u7684\u8d1f\u6574\u6570\u8868\u793a\u5f62\u5f0f\u3002<\/strong><\/p>\n<\/p>\n<p><h3><strong>\u4e94\u3001\u5339\u914d\u6b63\u8d1f\u6574\u6570<\/strong><\/h3>\n<\/p>\n<p><p>\u82e5\u9700\u5339\u914d\u6b63\u8d1f\u6574\u6570\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u5c06\u7ed3\u5408\u524d\u9762\u7684\u6a21\u5f0f\u8fdb\u884c\u8c03\u6574\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">\/^-?[1-9]\\d*$|^0+$\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u89e3\u8bfb\u8fd9\u4e2a\u8868\u8fbe\u5f0f\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>^-?<\/code> \u8868\u793a\u8d1f\u53f7\u53ef\u6709\u53ef\u65e0\u3002<\/li>\n<li><code>[1-9]\\d*<\/code> \u8868\u793a\u5339\u914d\u4ece1\u52309\u5f00\u59cb\u7684\u6574\u6570\u3002<\/li>\n<li><code>|^0+$<\/code> \u8868\u793a\u5339\u914d\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u96f6\u3002<\/li>\n<\/ul>\n<p><p><strong>\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u5141\u8bb8\u5339\u914d\u5230\u6b63\u6574\u6570\u3001\u8d1f\u6574\u6570\u4ee5\u53ca\u96f6\u3002<\/strong><\/p>\n<\/p>\n<p><h3><strong>\u516d\u3001\u5b9e\u9645\u4ee3\u7801\u5b9e\u73b0<\/strong><\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u73b0\u4e2d\uff0c\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u7b26\u5408\u6574\u6570\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function isInteger(str) {<\/p>\n<p>    let regex = \/^-?\\d+$\/;<\/p>\n<p>    return regex.test(str);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u8c03\u7528 <code>isInteger<\/code> \u51fd\u6570\u5e76\u4f20\u5165\u6240\u9700\u6821\u9a8c\u7684\u5b57\u7b26\u4e32\u3002\u8be5\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u6307\u793a\u8be5\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u6574\u6570\u3002<\/p>\n<\/p>\n<p><p>\u5728\u79fb\u52a8\u7aef\u9879\u76ee\u4e2d\u4f7f\u7528\u65f6\uff0c\u8be5\u51fd\u6570\u53ef\u4ee5\u5728\u5404\u79cd\u8f93\u5165\u6821\u9a8c\u573a\u666f\u4e2d\u8c03\u7528\uff0c\u4f8b\u5982\u8868\u5355\u63d0\u4ea4\u524d\u7684\u6570\u636e\u9a8c\u8bc1\u73af\u8282\u3002<\/p>\n<\/p>\n<p><h3><strong>\u4e03\u3001\u6027\u80fd\u4f18\u5316<\/strong><\/h3>\n<\/p>\n<p><p>\u5728\u79fb\u52a8\u7aef\u9879\u76ee\u4e2d\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u8fd8\u9700\u6ce8\u610f\u6027\u80fd\u4f18\u5316\u3002\u9891\u7e41\u521b\u5efa\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u8c61\u53ef\u80fd\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u6027\u80fd\u3002\u5982\u679c\u8fd9\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u5728\u4ee3\u7801\u4e2d\u4f1a\u88ab\u591a\u6b21\u4f7f\u7528\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u5176\u58f0\u660e\u4e3a\u5e38\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">const INTEGER_REGEX = \/^-?\\d+$\/;<\/p>\n<p>function isInteger(str) {<\/p>\n<p>    return INTEGER_REGEX.test(str);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u5b58\u50a8\u4e3a\u5e38\u91cf\uff0c\u907f\u514d\u4e86\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u91cd\u65b0\u7f16\u8bd1\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u63d0\u5347\u4e86\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u6548\u7387\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u603b\u7ed3\u6765\u8bf4\uff0c\u5728\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u5408\u7406\u4f7f\u7528JavaScript\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5339\u914d\u6574\u6570\u53ef\u4ee5\u5927\u5927\u63d0\u5347\u6570\u636e\u9a8c\u8bc1\u73af\u8282\u7684\u6548\u7387\u548c\u51c6\u786e\u6027\u3002\u4e86\u89e3\u5e76\u638c\u63e1\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u7f16\u5199\u4e0e\u5e94\u7528\uff0c\u5bf9\u4e8e\u5f00\u53d1\u7a33\u5b9a\u9ad8\u6548\u7684\u79fb\u52a8\u5e94\u7528\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u5728\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4e2d\u4f7f\u7528 JavaScript \u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6574\u6570\u5339\u914d\uff1f<\/strong><\/p>\n<p>\u5728\u79fb\u52a8\u7aef\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5339\u914d\u6574\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u521b\u5efa\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7528\u4e8e\u5339\u914d\u6574\u6570\nvar regex = \/^\\d+$\/;\n\n\/\/ \u6d4b\u8bd5\u5339\u914d\nvar myNumber = &quot;123&quot;;\nif(regex.test(myNumber)) {\n  console.log(&quot;\u5339\u914d\u6210\u529f\uff01&quot;);\n} else {\n  console.log(&quot;\u5339\u914d\u5931\u8d25\uff01&quot;);\n}\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u7684\u6b63\u5219\u8868\u8fbe\u5f0f <code>^\\d+$<\/code> \u8868\u793a\u4ece\u5b57\u7b26\u4e32\u7684\u5f00\u5934 <code>^<\/code> \u5230\u7ed3\u5c3e <code>$<\/code> \u5339\u914d\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u5b57 <code>\\d<\/code>\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5c06\u4e00\u4e2a\u6574\u6570\u5b57\u7b26\u4e32\u4f20\u9012\u7ed9 <code>test()<\/code> \u65b9\u6cd5\uff0c\u5b83\u5c06\u8fd4\u56de <code>true<\/code>\uff0c\u8868\u793a\u5339\u914d\u6210\u529f\u3002<\/p>\n<p><strong>2. \u5728\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u5982\u4f55\u4f7f\u7528 JavaScript \u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6574\u6570\u5339\u914d\uff0c\u4ee5\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u5224\u65ad\uff1f<\/strong><\/p>\n<p>\u5728\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u66f4\u9ad8\u7ea7\u529f\u80fd\u6765\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u6574\u6570\u5339\u914d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u521b\u5efa\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7528\u4e8e\u5339\u914d\u6574\u6570\nvar regex = \/^(?:-?(?:0|[1-9]\\d*))$\/;\n\n\/\/ \u6d4b\u8bd5\u5339\u914d\nvar myNumber = &quot;-123&quot;;\nif(regex.test(myNumber)) {\n  console.log(&quot;\u5339\u914d\u6210\u529f\uff01&quot;);\n} else {\n  console.log(&quot;\u5339\u914d\u5931\u8d25\uff01&quot;);\n}\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u7684\u6b63\u5219\u8868\u8fbe\u5f0f <code>^(?:-?(?:0|[1-9]\\d*))$<\/code> \u53ef\u4ee5\u5339\u914d\u5305\u62ec\u6b63\u8d1f\u53f7\u5728\u5185\u7684\u6574\u6570\u3002\u6240\u4ee5\uff0c\u5982\u679c\u5c06\u4e00\u4e2a\u5e26\u6709\u6b63\u8d1f\u53f7\u7684\u6574\u6570\u5b57\u7b26\u4e32\u4f20\u9012\u7ed9 <code>test()<\/code> \u65b9\u6cd5\uff0c\u5b83\u5c06\u8fd4\u56de <code>true<\/code>\uff0c\u8868\u793a\u5339\u914d\u6210\u529f\u3002<\/p>\n<p><strong>3. \u5728\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u5982\u4f55\u4f7f\u7528 JavaScript \u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6574\u6570\u5339\u914d\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\uff1f<\/strong><\/p>\n<p>\u5728\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u7684\u6761\u4ef6\u4f7f\u7528 JavaScript \u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6574\u6570\u5339\u914d\u3002\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u5b9e\u73b0\u66f4\u7cbe\u786e\u7684\u5339\u914d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u521b\u5efa\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7528\u4e8e\u5339\u914d\u6307\u5b9a\u8303\u56f4\u5185\u7684\u6574\u6570\uff0810-100\u4e4b\u95f4\uff09\nvar regex = \/^(?:10[0-9]|100)$\/;\n\n\/\/ \u6d4b\u8bd5\u5339\u914d\nvar myNumber = &quot;90&quot;;\nif(regex.test(myNumber)) {\n  console.log(&quot;\u5339\u914d\u6210\u529f\uff01&quot;);\n} else {\n  console.log(&quot;\u5339\u914d\u5931\u8d25\uff01&quot;);\n}\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f <code>^(?:10[0-9]|100)$<\/code> \u53ef\u4ee5\u5339\u914d10\u5230100\u4e4b\u95f4\u7684\u6574\u6570\u3002\u56e0\u6b64\uff0c\u53ea\u6709\u5728\u4f7f\u7528\u8303\u56f4\u5185\u7684\u6574\u6570\u5b57\u7b26\u4e32\u65f6\uff0c<code>test()<\/code> \u65b9\u6cd5\u624d\u4f1a\u8fd4\u56de <code>true<\/code>\uff0c\u8868\u793a\u5339\u914d\u6210\u529f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u79fb\u52a8\u7aef\u9879\u76ee\u5f00\u53d1\u4f7f\u7528JavaScript\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6574\u6570\u5339\u914d\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u6a21\u5f0f\u5b9e\u73b0\uff0c\u5177\u4f53\u5305\u62ec\uff1a\u7f16\u5199\u4e00\u4e2a\u5339\u914d\u6b63\u6574 [&hellip;]","protected":false},"author":3,"featured_media":155191,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/155184"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=155184"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/155184\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/155191"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=155184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=155184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=155184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}