{"id":161,"date":"2015-09-10T09:05:21","date_gmt":"2015-09-10T07:05:21","guid":{"rendered":"https:\/\/celilsemi.erkiner.com\/blog\/?p=161"},"modified":"2020-05-25T05:00:32","modified_gmt":"2020-05-25T03:00:32","slug":"validate-turkish-id-number-with-jquery-validation-plugin","status":"publish","type":"post","link":"https:\/\/celilsemi.erkiner.com\/blog\/validate-turkish-id-number-with-jquery-validation-plugin\/","title":{"rendered":"Validate Turkish ID Number with jQuery Validation Plugin"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">What is jQuery Validation Plugin?<\/h2>\n\n\n\n<p>The<a href=\"https:\/\/github.com\/jquery-validation\/jquery-validation\" target=\"_blank\" rel=\"noreferrer noopener\"> jQuery Validation Plugin<\/a> provides drop-in validation for your existing forms, while making all kinds of customizations to fit your application really easy.<\/p>\n\n\n\n<p>This jQuery plugin offers a lot of customization options while simplifying simple client-side form validation. It&#8217;s a good choice if you&#8217;re creating something new from scratch, but trying to integrate something with lots of existing markups into an existing app. The plugin provides an API for writing your own methods, while it comes with a number of useful verification methods, including URL and email verification. All the bundled methods are translated into English default error messages and 37 other languages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is missing?<\/h2>\n\n\n\n<p>An additional method that validates Turkish identification numbers (aka T.C. Kimlik No). The plugin is really widely used on Turkish websites and provides out of the box validations for many necessary types. But this one important validation is missing for Turkish developers. The moment I realised, I have developed an extension and raised <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/jquery-validation\/jquery-validation\/pull\/1555\" target=\"_blank\">a pull request<\/a> to the maintained of this plugin.<\/p>\n\n\n\n<p><strong>Unfortunately, my efforts to improve this jQuery plugin was not appreciated \ud83d\ude41<\/strong><\/p>\n\n\n\n<p>Maintainer replied, &#8220;<em>As we dont yet support citizen numbers for other countries I am not willing to merge this.<\/em>&#8220;.  Although they already have a few non-core validators in their additional folder, mine was not accepted. By &#8220;a few&#8221;, I meant not 1, not 2, but 48 additional scripts!!! Mine was not worthy enough to merge&#8230; \ud83d\ude41<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Validation of Turkish ID Number<\/h2>\n\n\n\n<p>It is quite simple after including my additional method js along with jquery-validation plugin.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">\/*\n * Returns true, if the value is a well formatted turkish identification number (T.C. Kimlik No).\n *\n * Better to use with minlength, maxlength, digits.\n *\n * Example: tcnoInputName: {minlength: 11, maxlength: 11, digits: true, idTR: true}\n *\n *\/\n$.validator.addMethod(&quot;idTR&quot;, function(value, element) {\n    var d = value.split(&quot;&quot;), t = 0, e = 0, o = 0, i, n;\n    for (i = 0; i &lt; 9; i++) {\n        n = parseInt(d[i], 10);\n        t += n;\n        if (i % 2 === 1) {\n            e += n;\n        } else {\n            o += n;\n        }\n    }\n    return this.optional(element) || !(!\/^[1-9][0-9]{10}$\/.test(value) || ( (t + parseInt(d[9], 10)) % 10 !== d[10]) || (o * 7 - e) % 10 !== d[9]);\n}, $.validator.messages.remote);<\/pre><\/div>\n\n\n\n<p>Include this file after jQuery and jQuery-validation but before your validation logic. <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">$('formName').validate({\n    rules : {\n        inputName : { idTR : true }\n    }\n});<\/pre><\/div>\n\n\n\n<p>You can use it simply by stating that the input under the form should return true for &#8220;idTR&#8221;.<\/p>\n\n\n\n<p>I hope you will find this information useful. If you enjoyed this post, I\u2019d be very grateful if you\u2019d help it spread by emailing it to a friend, or sharing it on Twitter or Facebook. Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is jQuery Validation Plugin? The jQuery Validation Plugin provides drop-in validation for your existing forms, while making all kinds of customizations to fit your application really easy. This jQuery plugin offers a lot of customization options while simplifying simple client-side form validation. It&#8217;s a good choice if you&#8217;re creating something new from scratch, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[7],"tags":[4,26,27],"class_list":["post-161","post","type-post","status-publish","format-standard","hentry","category-front-end","tag-javascript","tag-jquery","tag-plugin"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":2,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions\/166"}],"wp:attachment":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}