{"id":954,"date":"2020-10-02T16:29:57","date_gmt":"2020-10-02T07:29:57","guid":{"rendered":"https:\/\/www.wetch.co.jp\/?p=954"},"modified":"2022-01-14T23:16:14","modified_gmt":"2022-01-14T14:16:14","slug":"only-numbers-input","status":"publish","type":"post","link":"https:\/\/www.wetch.co.jp\/note\/only-numbers-input\/","title":{"rendered":"[JS]input\u306b\u534a\u89d2\u6570\u5b57\u306e\u307f\u5165\u529b\u3055\u305b\u305f\u3044\uff01\uff08\u5168\u534a\u5909\u63db\u4ed8\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">input\u306b\u6570\u5b57\u306e\u307f\u5165\u529b\u3055\u305b\u305f\u3044\u6642\u3001type=&#8221;number&#8221;\u3092\u4f7f\u3063\u3066\u307e\u3059\u304b\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306etype=&#8221;number&#8221;\u3001\u5b9f\u306f\u6570\u5b57\u4ee5\u5916\u306b+\uff08\u30d7\u30e9\u30b9\uff09\u3068-\uff08\u30de\u30a4\u30ca\u30b9\uff09\u3001.\uff08\u5c0f\u6570\u70b9\uff09\u3042\u3068e\uff08\u6307\u6570\u8868\u8a18\uff09\u3092\u5165\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u6570\u3057\u304b\u60f3\u5b9a\u3057\u3066\u3044\u306a\u3044\u30b7\u30b9\u30c6\u30e0\u306b\u3053\u308c\u3089\u306e\u6587\u5b57\u304c\u5165\u529b\u3055\u308c\u308b\u3068\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u305d\u3053\u3067js\u3067\u534a\u89d2\u6570\u5b57\u306e\u307f\u5165\u529b\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u3064\u3044\u3067\u306b\u5168\u89d2\u6570\u5b57\u3092\u81ea\u52d5\u3067\u534a\u89d2\u6570\u5b57\u306b\u5909\u63db\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5168\u89d2\u2192\u534a\u89d2\u5909\u63db\u4ed8\u304d\u6570\u5b57\u3060\u3051\u5165\u529b\u3067\u304d\u308b\u30d5\u30a3\u30fc\u30eb\u30c9<\/strong><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;input type=&quot;text&quot;&gt;\n\u2193\n&amp;lt;input type=&quot;text&quot; oninput=&quot;value = value.replace(\/&#x5B;\uff10-\uff19]\/g,s =&gt; String.fromCharCode(s.charCodeAt(0) - 65248)).replace(\/\\D\/g,&#039;&#039;);&quot;&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">\u9806\u306b\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">type=\"text\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u77e2\u5370\uff08\u30b9\u30d4\u30f3\u30dc\u30bf\u30f3\uff09\u304c\u8868\u793a\u3055\u308c\u306a\u3044\u3088\u3046&#8221;text&#8221;\u306b\u3057\u3066\u3042\u308a\u307e\u3059\u3002\u4eca\u56de\u306fjs\u5074\u3067\u5165\u529b\u5236\u9650\u3092\u3059\u308b\u306e\u3067\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">oninput=\" ~~ \"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5165\u529b\u3055\u308c\u305f\u6642\u306bjs\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">value = value.replace(\/[\uff10-\uff19]\/g,s =&gt; String.fromCharCode(s.charCodeAt(0) - 65248)).replace(\/\\D\/g,'');<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">input\u306e\u5185\u5bb9\u3092\u51e6\u7406\u3092\u3057\u3066\u4e0a\u66f8\u304d\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">replace\u304c\uff12\u56de\u7d9a\u3051\u3066\u5b9f\u884c\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\uff11\u56de\u76ee\u304c\u300c\uff10\u301c\uff19\uff08\u5168\u89d2\u6570\u5b57\uff09\u3092\u898b\u3064\u3051\u3066\u534a\u89d2\u6570\u5b57\u306b\u5909\u63db\u300d\u3001\uff12\u56de\u76ee\u306b\u300c\u6570\u5b57\u4ee5\u5916\u3092\u524a\u9664\u300d\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u95a2\u6570\u5316<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5165\u529b\u5236\u9650\u3092\u3057\u305f\u3044\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u8907\u6570\u3042\u308b\u5834\u5408\u306f\u95a2\u6570\u5316\u3057\u3066\u7c21\u5358\u306b\u547c\u3073\u51fa\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nHTML\n&amp;lt;input type=&quot;text&quot; oninput=&quot;value = onlyNumbers(value)&quot;&gt;\n\nJS\nconst onlyNumbers = n =&gt; {\n    return n.replace(\/&#x5B;\uff10-\uff19]\/g,s =&gt; String.fromCharCode(s.charCodeAt(0) - 65248)).replace(\/\\D\/g,&#039;&#039;);\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>\u304a\u307e\u3051\uff1a\u96fb\u8a71\u756a\u53f7\u30d0\u30fc\u30b8\u30e7\u30f3<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5168\u89d2\u2192\u534a\u89d2\u5909\u63db\u3068\u30cf\u30a4\u30d5\u30f3\u3068\u6570\u5b57\u306e\u307f\u5165\u529b<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nreturn n.replace(\/&#x5B;\uff10-\uff19]\/g,s =&gt; String.fromCharCode(s.charCodeAt(0) - 65248)).replace(\/&#x5B;\u30fc\u2212]\/g,&#039;-&#039;).replace(\/&#x5B;^\\-\\d]\/g,&#039;&#039;);\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>input\u306b\u6570\u5b57\u306e\u307f\u5165\u529b\u3055\u305b\u305f\u3044\u6642\u3001type=&#8221;number&#8221;\u3092\u4f7f\u3063\u3066\u307e\u3059\u304b\uff1f<br \/>\n\u3053\u306etype=&#8221;number&#8221;\u3001\u5b9f\u306f\u6570\u5b57\u4ee5\u5916\u306b+\uff08\u30d7\u30e9\u30b9\uff09\u3068-\uff08\u30de\u30a4\u30ca\u30b9\uff09\u3001.\uff08\u5c0f\u6570\u70b9\uff09\u3042\u3068e\uff08\u6307\u6570\u8868\u8a18\uff09\u3092\u5165\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u6574\u6570\u3057\u304b\u60f3\u5b9a\u3057\u3066\u3044\u306a\u3044\u30b7\u30b9\u30c6\u30e0\u306b\u3053\u308c\u3089\u306e\u6587\u5b57\u304c\u5165\u529b\u3055\u308c\u308b\u3068\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u305d\u3053\u3067js\u3067\u534a\u89d2\u6570\u5b57\u306e\u307f\u5165\u529b\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u3064\u3044\u3067\u306b\u5168\u89d2\u6570\u5b57\u3092\u81ea\u52d5\u3067\u534a\u89d2\u6570\u5b57\u306b\u5909\u63db\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n","protected":false},"author":9,"featured_media":965,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[214],"tags":[24,25,35,37],"class_list":["post-954","post","type-post","status-publish","format-standard","has-post-thumbnail","category-214","tag-web","tag-25","tag-35","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/comments?post=954"}],"version-history":[{"count":0,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/954\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media\/965"}],"wp:attachment":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media?parent=954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/categories?post=954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/tags?post=954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}