{"id":117,"date":"2020-06-02T21:28:49","date_gmt":"2020-06-02T21:28:49","guid":{"rendered":"http:\/\/bahadirmeric.net\/bahadir\/?p=117"},"modified":"2020-06-02T21:28:49","modified_gmt":"2020-06-02T21:28:49","slug":"javascriptten-sadece-numara-girisi-saglayalim","status":"publish","type":"post","link":"http:\/\/bahadirmeric.net\/bahadir\/2020\/06\/02\/javascriptten-sadece-numara-girisi-saglayalim\/","title":{"rendered":"JavaScript\u2019ten sadece Numara Giri\u015fi sa\u011flayal\u0131m"},"content":{"rendered":"\n<p>Web sitelerinde bazen sadece say\u0131 girebilece\u011fimiz baz\u0131 giri\u015f kutucuklar\u0131na ihtiya\u00e7 duyar\u0131z. Baz\u0131lar\u0131m\u0131z bu durumu \u201c<strong>Validation<\/strong>\u201d nesnesi ile sa\u011flar. Bir yol daha var tabi \u00fc\u00e7\u00fcnc\u00fc parti uygulamalar ile de bu kontroll\u00fc sa\u011flayabilirsiniz. Fakat bunlardan en kolay\u0131 a\u015fa\u011f\u0131da sizlerle payla\u015ft\u0131\u011f\u0131m kod dur.<\/p>\n\n\n\n<p>Bu arada bu kod vas\u0131tas\u0131yla sadece rakam de\u011fil \u00f6rne\u011fin beraberinde \u201c<strong>\u2013<\/strong>\u201d karakteri yada sizlerin belirleyece\u011fi her hangi bir karakterinde beraberinde bas\u0131lmas\u0131n\u0131 sa\u011flayabilirsiniz. Bunun i\u00e7in a\u015fa\u011f\u0131da g\u00f6rm\u00fc\u015f oldu\u011funuz kod par\u00e7ac\u0131\u011f\u0131nda ki \u201c<strong>OnKeypress<\/strong>\u201d fonksiyonuna ait kodu \u015fu \u015fekilde d\u00fczenlemem yetecek; &nbsp;<strong>onkeypress=\u201dreturn SadeceRakam(event,[\u2018-\u2018]);\u201d<\/strong><\/p>\n\n\n\n<p>A\u015fa\u011f\u0131daki kodu &lt;head&gt;&lt;\/head&gt; tag\u2019leri aras\u0131na yazmay\u0131 unutmuyoruz !!!<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n&lt;script type=&quot;text\/javascript&quot;&gt;\n        function SadeceRakam(e, allowedchars) {\n            var key = e.charCode == undefined ? e.keyCode : e.charCode;\n            if ((\/^&#x5B;0-9]+$\/.test(String.fromCharCode(key))) || key == 0 || key == 13 || isPassKey(key, allowedchars)) { return true; }\n            else { return false; }\n        }\n \n        function isPassKey(key, allowedchars) {\n            if (allowedchars != null) {\n                for (var i = 0; i &lt; allowedchars.length; i++) {\n                    if (allowedchars&#x5B;i] == String.fromCharCode(key))\n                        return true;\n                }\n            }\n            return false;\n        }\n \n        function SadeceRakamBlur(e, clear) {\n            var nesne = e.target ? e.target : e.srcElement;\n            var val = nesne.value;\n            val = val.replace(\/^\\s+|\\s+$\/g, &quot;&quot;);\n            if (clear) val = val.replace(\/\\s{2,}\/g, &quot; &quot;);\n            nesne.value = val;\n        }\n    &lt;\/script&gt;\n<\/pre><\/div>\n\n\n<p>Bununla birlikte hangi buton kutusuna bu kodu ba\u011flamak istiyorsak ta a\u015fa\u011f\u0131daki gibi buton kutusuna ba\u011flamay\u0131 atlam\u0131yoruz ki \u00e7al\u0131\u015fs\u0131n;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n&lt;asp:TextBox ID=&quot;txtPhone&quot; runat=&quot;server&quot; onkeypress=&quot;return SadeceRakam(event);&quot; onblur=&quot;SadeceRakam(event,false)&quot; MaxLength=&quot;11&quot;&gt;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Web sitelerinde bazen sadece say\u0131 girebilece\u011fimiz baz\u0131 giri\u015f kutucuklar\u0131na ihtiya\u00e7 duyar\u0131z. Baz\u0131lar\u0131m\u0131z bu durumu \u201cValidation\u201d nesnesi ile sa\u011flar. Bir yol daha var tabi \u00fc\u00e7\u00fcnc\u00fc parti uygulamalar ile de bu kontroll\u00fc sa\u011flayabilirsiniz. Fakat bunlardan en kolay\u0131 a\u015fa\u011f\u0131da sizlerle payla\u015ft\u0131\u011f\u0131m kod dur. Bu arada bu kod vas\u0131tas\u0131yla sadece rakam de\u011fil \u00f6rne\u011fin beraberinde&#8230; <a class=\"continue-reading-link\" href=\"http:\/\/bahadirmeric.net\/bahadir\/2020\/06\/02\/javascriptten-sadece-numara-girisi-saglayalim\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":12,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[12,6],"class_list":["post-117","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-javascript","tag-visual-studio"],"_links":{"self":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":1,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":118,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/117\/revisions\/118"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/media\/12"}],"wp:attachment":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}