<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nattster &#187; javascript</title>
	<atom:link href="http://nattster.siamdev.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://nattster.siamdev.net</link>
	<description>ลั่ลล้า...</description>
	<lastBuildDate>Sun, 25 Dec 2011 05:13:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Nontri Internet Auto-login: firefox Extension 1.1</title>
		<link>http://nattster.siamdev.net/2008/09/firefox-extension-nontri-auto-login/</link>
		<comments>http://nattster.siamdev.net/2008/09/firefox-extension-nontri-auto-login/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 08:05:37 +0000</pubDate>
		<dc:creator>nattster</dc:creator>
				<category><![CDATA[คอมพิวเตอร์จ๋า]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[nontri]]></category>
		<category><![CDATA[xul]]></category>

		<guid isPermaLink="false">http://nattster.siamdev.net/?p=55</guid>
		<description><![CDATA[หลายคนที่ใช้อินเตอร์เน็ตเกษตร (เช่นผม) อาจจะเจอกับหน้าเว็บ login ทุกครั้งที่ต้องการเข้าอินเตอร์เน็ต เนื่องจากมหาลัยฯต้องจัดเก็บบันทึกการใช้งานอินเตอร์เน็ต ตามพรบ. คอมฯ ถ้าใช้เครื่องส่วนตัวอยู่อาจแก้ปัญหาโดยการให้ browser ช่วยจำ password ได้ (แต่มีเครื่องเซิร์ฟเวอร์ 10 เครื่องสำหรับ login แปลว่าต้อง save password ไว้สำหรับ 10 เซิร์ฟเวอร์ อาจทำได้ง่ายๆ แต่ผมทำไม่เป็น เลยเขียนโปรแกรมดีกว่า) ก่อนหน้านี้เคยเขียนโปรแกรมช่วย login ด้วย C# (แต่หลายคนเอาไปใช้แล้วก็เจอ bug shutdown ไม่ลง รวมทั้ง password ยังถูกเก็บเป็น plain-text บนเครื่องด้วย) เลยตัดสินใจลองเขียน Firefox Extension (ไม่แก้ bug โปรแกรมเดิม แต่เขียนใหม่เลย &#8211; -&#8221;) พอจะเขียน Extension ก็ค้นๆ ไปเจอ Building an Extension [...]]]></description>
			<content:encoded><![CDATA[<p>หลายคนที่ใช้อินเตอร์เน็ตเกษตร (เช่นผม) อาจจะเจอกับหน้าเว็บ login ทุกครั้งที่ต้องการเข้าอินเตอร์เน็ต เนื่องจากมหาลัยฯต้องจัดเก็บบันทึกการใช้งานอินเตอร์เน็ต ตามพรบ. คอมฯ ถ้าใช้เครื่องส่วนตัวอยู่อาจแก้ปัญหาโดยการให้ browser ช่วยจำ password ได้ (แต่มีเครื่องเซิร์ฟเวอร์ 10 เครื่องสำหรับ login แปลว่าต้อง save password ไว้สำหรับ 10 เซิร์ฟเวอร์ อาจทำได้ง่ายๆ แต่ผมทำไม่เป็น เลยเขียนโปรแกรมดีกว่า)</p>
<div id="attachment_57" class="wp-caption alignleft" style="width: 207px"><a href="http://nattster.siamdev.net/wp-content/uploads/2008/09/screenshot.png" rel="lightbox[55]" title="autologin screenshot"><img class="size-full wp-image-57" title="autologin screenshot" src="http://nattster.siamdev.net/wp-content/uploads/2008/09/screenshot.png" alt="Nontri Internet Auto-login screenshot" width="197" height="133" /></a><p class="wp-caption-text">วิธีใช้โปรแกรม</p></div>
<p>ก่อนหน้านี้เคยเขียนโปรแกรมช่วย login ด้วย C# (แต่หลายคนเอาไปใช้แล้วก็เจอ bug shutdown ไม่ลง รวมทั้ง password ยังถูกเก็บเป็น plain-text บนเครื่องด้วย) เลยตัดสินใจลองเขียน Firefox Extension (ไม่แก้ bug โปรแกรมเดิม แต่เขียนใหม่เลย &#8211; -&#8221;)</p>
<p>พอจะเขียน Extension ก็ค้นๆ ไปเจอ <a href="http://developer.mozilla.org/en/Building_an_Extension">Building an Extension</a> สอนเขียนทีละขั้นตอน ช่วยให้หัดเขียนได้เร็วมาก ใช้เวลาประมาณ 3 ชม. (ระหว่างเรียน assembly) รวมเวลาศึกษา doc จาก <a href="http://developer.mozilla.org/en/Extensions">mozilla &lt;developer center /&gt;</a> ด้วยครับ</p>
<p><span style="color: #339966;"><strong>Username และ Password จะถูกเก็บ(แบบเข้ารหัส)ด้วย Firefox Password Manager </strong></span></p>
<h2><span style="color: #0000ff;"><strong>วิธีติดตั้ง</strong></span></h2>
<p>1. ดาวน์โหลด <a onclick="InstallTrigger.startSoftwareUpdate('http://nattster.siamdev.net/wp-content/uploads/2008/09/autologin.xpi', null); return false;" href="http://nattster.siamdev.net/wp-content/uploads/2008/09/autologin.xpi">autologin Extension</a> (9kb) และติดตั้งเหมือน extension อื่นๆ โดย &#8220;กดปุ่ม Install&#8221;</p>
<p><span style="color: #ff0000;"><strong>2. อย่าลืม! ติดตั้ง Certificate ของ KU ก่อน</strong></span> ไม่งั้นโปรแกรมไม่เวิร์ค ที่ <a href="http://ca.ku.ac.th/ssl.crt/ROOT-KU-CA.crt">http://ca.ku.ac.th/ssl.crt/ROOT-KU-CA.crt</a></p>
<p>3. คลิกขวา เพื่อกำหนด username/password ก่อนครับ <strong><span style="color: #0000ff;">(ตอนนี้ถ้า browser redirect ไปหน้า login เมื่อไหร่โปรแกรมจะ login ให้อัตโนมัติทันทีครับ)</span></strong></p>
<p><b><font color="red" size="+1">ปล. ตอนนี้โปรแกรมใช้ไม่ได้แล้วครับ มหาลัยเปลี่ยน หน้า login ใหม่อีกนิดหน่อย&#8230;. รอใช้โปรแกรมของ jtf ครับ <img src='http://nattster.siamdev.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </font></b><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://nattster.siamdev.net/2008/09/firefox-extension-nontri-auto-login/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>มาดูวิธีเช็ค ว่า &#8220;เขามั่วรหัสประชาชนรึเปล่า?&#8221;</title>
		<link>http://nattster.siamdev.net/2006/09/id-verification/</link>
		<comments>http://nattster.siamdev.net/2006/09/id-verification/#comments</comments>
		<pubDate>Fri, 08 Sep 2006 08:37:21 +0000</pubDate>
		<dc:creator>nattster</dc:creator>
				<category><![CDATA[คอมพิวเตอร์จ๋า]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://nattster.siamdev.net/?p=4</guid>
		<description><![CDATA[ขอเริ่มบทความแบบพิสดารบ้างได้ไหมครับ ก่อนอ่านบทความต่อไป ผมขอนำเสนอ หมอดูที่ชื่อว่า &#8220;แม่นมั่กๆ&#8221; หมอดู แม่นมั่กๆ หมอดู แม่นมั่กๆ สามารถทำนายรหัสประชาชนหลักที่ 13 จาก รหัสประชาชน 12 หลักแรกได้ครับ ไม่เชื่อก็ลองกรอกรหัสประชาชน 12 หลักแรกลงในช่องต่อไปนี้ดูครับ รหัสประชาชน โอ๊ะ ทำได้ไงเนี่ย อยากรู้หละสิ ถ้าอยากรู้มาลองอ่านบทความต่อสิครับ ^_^ รหัสประจำตัวประชาชน (ขอเรียกสั้นๆว่า รหัสประชาชน) ที่เราจะมาตรวจกันวันนี้เป็นรหัสประชาชน ของคนไทยนะครับ ก่อนอื่น ให้เพื่อนๆ หยิบบัตรประชาชนของเพื่อนๆ ขึ้นมาดูกันเลยครับ รหัสประจำตัวของเราจะอยู่ในรูป x-xxxx-xxxxx-xx-x (เลข 13 หลัก) ใช่มั้ยครับ แต่เพื่อนๆ รู้ป่ะว่า จริงๆแล้ว รหัสประจำตัวของเราเนี่ย จริงๆ แล้วมีแค่ 12 หลักเท่านั้น (12 หลักแรก) แต่เลขตัวสุดท้ายเนี่ย เป็น Check Digit ครับ Check [...]]]></description>
			<content:encoded><![CDATA[<p>ขอเริ่มบทความแบบพิสดารบ้างได้ไหมครับ ก่อนอ่านบทความต่อไป ผมขอนำเสนอ หมอดูที่ชื่อว่า &#8220;แม่นมั่กๆ&#8221;</p>
<h3>หมอดู แม่นมั่กๆ</h3>
<p>หมอดู แม่นมั่กๆ สามารถทำนายรหัสประชาชนหลักที่ 13 จาก รหัสประชาชน 12 หลักแรกได้ครับ ไม่เชื่อก็ลองกรอกรหัสประชาชน 12 หลักแรกลงในช่องต่อไปนี้ดูครับ</p>
<div style="margin: 10px; padding: 10px; width: 300px; background-color: #f1f1f1;">
<form name="wiz" onsubmit="predict(document.wiz.id.value); return false;">รหัสประชาชน</p>
<input maxlength="12" name="id" size="12" type="text" />
<input onclick="return predict(document.wiz.id.value);" type="submit" value="ทำนายสิ" />
<script src="http://nattster.siamdev.net/tmp/predictor.js" type="text/javascript"></script><br />
 </form>
<div id="lnum"><!-- --></div>
</div>
<p>โอ๊ะ ทำได้ไงเนี่ย อยากรู้หละสิ ถ้าอยากรู้มาลองอ่านบทความต่อสิครับ ^_^  <span id="more-4"></span> รหัสประจำตัวประชาชน (ขอเรียกสั้นๆว่า รหัสประชาชน) ที่เราจะมาตรวจกันวันนี้เป็นรหัสประชาชน  ของคนไทยนะครับ ก่อนอื่น ให้เพื่อนๆ หยิบบัตรประชาชนของเพื่อนๆ ขึ้นมาดูกันเลยครับ  รหัสประจำตัวของเราจะอยู่ในรูป x-xxxx-xxxxx-xx-x (เลข 13 หลัก) ใช่มั้ยครับ แต่เพื่อนๆ รู้ป่ะว่า  จริงๆแล้ว รหัสประจำตัวของเราเนี่ย จริงๆ แล้วมีแค่ 12 หลักเท่านั้น (12 หลักแรก) แต่เลขตัวสุดท้ายเนี่ย  เป็น Check Digit ครับ</p>
<h3>Check Digit คืออะไรหนอ?</h3>
<p>Check Digit เป็นตัวเลข 1 หลัก ที่เกิดจากการนำเลขหลักอื่นๆ มา บวก ลบ คูณ หาร กัน และ  Check Digit นี่หละครับ จะช่วยให้เราตรวจสอบในเบื้องต้นได้ว่า ข้อมูลที่กรอกมาถูกต้องรึเปล่า  เวลาเราจะตรวจสอบว่าข้อมูลที่กรอกมาถูกต้องรึเปล่า เราจะคำนวณ Check Digit จากเลขหลักอื่นๆ  เพื่อเปรียบเทียบกับ Check Digit ที่เขากรอกมาว่าตรงกันมั้ย ถ้าตรงกันก็แสดงว่าข้อมูลถูกต้องไม่ผิด ไม่มั่ว  แต่ถ้าไม่ตรงกัน ก็แปลว่า ข้อมูลที่กรอกมามีข้อมูลซักหลัก หรือ สองหลักที่ผิด เราก็สามารถเตือนให้ผู้ใช้ทราบและกรอกใหม่  อีกครั้งได้</p>
<h3>เอ้า มาลองคำนวณ Check Digit ของรหัสประชาชนเรากันดีกว่า</h3>
<p>ขอยกตัวอย่างรหัสประชาชนนี้ละกันครับ  <code class="geshifilter text">1-2015-41462-23-4</code> ไหน ตอบหน่อยซิ ว่า Check Digit ของรหัสประชาชนนี้คือเลขอะไรคร้าบ&#8230;&#8230;.  เอ้า ถามเองตอบเองก็ได้ Check Digit ของรหัสประชาชนนี้คือเลข 4 (เลขตัวสุดท้ายนั่นเอง)  เรามาดูกันว่า เลข 4 เกิดจากอะไรหว่า? คำนวณมาได้ไง? มั่วอ๊ะเปล่า?</p>
<ul>
<li><span class="att">ขั้นตอนที่ 1</span> &#8211; เอาเลข 12 หลักมา เขียนแยกหลักกันก่อน (หลักที่ 13 ไม่ต้องเอามานะคร้าบ)<br />
<table style="border-color: #000000; border-collapse: collapse;" border="1">
<tbody>
<tr>
<th width="20">1</th>
<th width="20">2</th>
<th width="20">0</th>
<th width="20">1</th>
<th width="20">5</th>
<th width="20">4</th>
<th width="20">1</th>
<th width="20">4</th>
<th width="20">6</th>
<th width="20">2</th>
<th width="20">2</th>
<th width="20">3</th>
</tr>
</tbody>
</table>
</li>
<li><span class="att">ขั้นตอนที่ 2</span> &#8211; เอาเลข 12 หลักนั้นมา คูณเข้ากับเลขประจำหลักของมัน<br />
<table style="border-color: #000000; border-collapse: collapse;" border="1">
<tbody>
<tr>
<th>รหัสบัตร</th>
<th width="20">1</th>
<th width="20">2</th>
<th width="20">0</th>
<th width="20">1</th>
<th width="20">5</th>
<th width="20">4</th>
<th width="20">1</th>
<th width="20">4</th>
<th width="20">6</th>
<th width="20">2</th>
<th width="20">2</th>
<th width="20">3</th>
</tr>
<tr>
<th>ตัวคูณ</th>
<th>13</th>
<th>12</th>
<th>11</th>
<th>10</th>
<th>9</th>
<th>8</th>
<th>7</th>
<th>6</th>
<th>5</th>
<th>4</th>
<th>3</th>
<th>2</th>
</tr>
<tr>
<th colspan="13" height="1"></th>
</tr>
<tr>
<th>ผลคูณ</th>
<th>13</th>
<th>24</th>
<th>0</th>
<th>10</th>
<th>45</th>
<th>32</th>
<th>7</th>
<th>24</th>
<th>30</th>
<th>8</th>
<th>6</th>
<th>6</th>
</tr>
</tbody>
</table>
</li>
<li><span class="att">ขั้นตอนที่ 3</span> &#8211; เอาผลคูณทั้ง 12 ตัวมา บวกกันทั้งหมด จะได้ 13+24+0+10+45+32+7+24+30+8+6+6=205</li>
<li><span class="att">ขั้นตอนที่ 4</span> &#8211; เอาเลขที่ได้จากขั้นตอนที่ 3 มา mod 11 (หารเอาเศษ) จะได้ 205 mod 11 = 7</li>
<li><span class="att">ขั้นตอนที่ 5</span> &#8211; เอา 11 ตั้ง ลบออกด้วย เลขที่ได้จากขั้นตอนที่ 4 จะได้ 11-7 = 4 (เราจะได้ 4 เป็นเลขในหลัก Check Digit)  ถ้าเกิด ลบแล้วได้ออกมาเป็นเลข 2 หลัก ให้เอาเลขในหลักหน่วยมาเป็น Check Digit (เช่น 11 ให้เอา 1 มา, 10 ให้เอา 0 มา เป็นต้น)</li>
</ul>
<p>โอ้โห&#8230;.มหัศจรรย์มาก ยอดเยี่ยมกระเทียมดอง เลขที่ได้ตรงกับเลขหลักที่ 13 ด้วยแหละ&#8230;ถ้าไม่เชื่อก็เอาเลขบัตรประชาชนตัวเองมาคำนวณดูสิครับ  ผมคิดว่าหลายๆ คนคงมีคำถามในใจแล้วหละว่า ทำไมต้องเอามาคูณ 13 ทำไมต้องเอามา บวกกัน ทำไมต้องเอามา mod 11 คำตอบที่ผมให้ได้ก็คือ  มันคือวิธีที่ถูกเลือกใช้ในการคำนวณ Check Digit ให้กับรหัสประชาชนครับ แต่ถ้าเราจะคำนวณ Check Digit ให้กับรหัสสินค้า หรือ ISBN ของหนังสือ เราก็ต้องใช้วิธีการคำนวณ  ที่แตกต่างกันออกไปครับ<br />
<script type="text/javascript"><!--
google_ad_client = "pub-5366864020460148";
/* 468x60, created 7/22/09 */
google_ad_slot = "8532721966";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h3>ในเมื่อรู้วิธีแล้ว เรามาเขียนโปรแกรมตรวจสอบกันดีกว่า</h3>
<p>ผมเขียนไว้ให้หลายภาษาเหมือนกัน ให้เพื่อนๆ เลือกใช้ได้ตามสะดวกนะครับ</p>
<h3>เวอร์ชัน JavaScript</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> checkID<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>id.<span style="color: #660066;">length</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> sum<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        sum <span style="color: #339933;">+=</span> parseFloat<span style="color: #009900;">&#40;</span>id.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">13</span><span style="color: #339933;">-</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">11</span><span style="color: #339933;">-</span>sum<span style="color: #339933;">%</span>11<span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span>10<span style="color: #339933;">!=</span>parseFloat<span style="color: #009900;">&#40;</span>id.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> checkForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>checkID<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">form1</span>.<span style="color: #660066;">txtID</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'รหัสประชาชนไม่ถูกต้อง'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'รหัสประชาชนถูกต้อง เชิญผ่านได้'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;form&gt;
รหัสประจำตัวประชาชน :
&lt;input name=&quot;txtID&quot; type=&quot;text&quot; /&gt;
&lt;input type=&quot;submit&quot; value=&quot;ตรวจสอบ&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<h3>เวอร์ชัน php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000000; font-weight: bold;">function</span> checkID<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sum</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$sum</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #339933;">-</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sum</span><span style="color: #339933;">%</span><span style="color:#800080;">11</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color:#800080;">10</span> <span style="color: #339933;">==</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form action=&quot;?&quot; method=&quot;get&quot;&gt;
รหัสประจำตัวประชาชน :
&lt;input name=&quot;txtID&quot; type=&quot;text&quot; /&gt;
&lt;input type=&quot;submit&quot; value=&quot;ตรวจสอบ&quot; /&gt;
&lt;/form&gt;
<span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'txtID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>checkID<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'txtID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;รหัสถูกต้องครับ&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">else</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;รหัสที่คุณกรอกไม่ถูกต้องค&quot;</span><span style="color: #339933;">;</span> รับ
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>เวอร์ชั่น ASP 3</h3>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #0000ff; font-weight: bold;">Function</span> checkID<span style="color: #006600; font-weight:bold;">&#40;</span>id<span style="color: #006600; font-weight:bold;">&#41;</span>
    checkID <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">False</span>
    <span style="color: #990099; font-weight: bold;">If</span> <span style="color: #330066;">Len</span><span style="color: #006600; font-weight:bold;">&#40;</span>id<span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">13</span> <span style="color: #990099; font-weight: bold;">Then</span>
        <span style="color: #990099; font-weight: bold;">Dim</span> i, sum
        <span style="color: #990099; font-weight: bold;">For</span> i <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">1</span> <span style="color: #990099; font-weight: bold;">To</span> <span style="color: #800000;">12</span>
            sum <span style="color: #006600; font-weight: bold;">=</span> sum + <span style="color: #990099; font-weight: bold;">CInt</span><span style="color: #006600; font-weight:bold;">&#40;</span>Mid<span style="color: #006600; font-weight:bold;">&#40;</span>id, i, <span style="color: #800000;">1</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight: bold;">*</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #800000;">14</span>-i<span style="color: #006600; font-weight:bold;">&#41;</span>
        <span style="color: #990099; font-weight: bold;">Next</span>
        <span style="color: #990099; font-weight: bold;">If</span> <span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #800000;">11</span>-<span style="color: #006600; font-weight:bold;">&#40;</span>sum Mod <span style="color: #800000;">11</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span> Mod <span style="color: #800000;">10</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #990099; font-weight: bold;">CInt</span><span style="color: #006600; font-weight:bold;">&#40;</span>Mid<span style="color: #006600; font-weight:bold;">&#40;</span>id, i, <span style="color: #800000;">13</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #990099; font-weight: bold;">Then</span>
            checkID <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">True</span>
        <span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
    <span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #0000ff; font-weight: bold;">Function</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span>
&lt;form action=&quot;?&quot; method=&quot;get&quot;&gt;
รหัสประจำตัวประชาชน :
&lt;input name=&quot;txtID&quot; type=&quot;text&quot; /&gt;
&lt;input type=&quot;submit&quot; value=&quot;ตรวจสอบ&quot; /&gt;
&lt;/form&gt;
<span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #990099; font-weight: bold;">If</span> <span style="color: #990099; font-weight: bold;">Request</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;txtID&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;&amp;</span>gt<span style="color: #006600; font-weight: bold;">;</span> <span style="color: #cc0000;">&quot;&quot;</span> <span style="color: #990099; font-weight: bold;">Then</span>
    <span style="color: #990099; font-weight: bold;">If</span> checkID<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #990099; font-weight: bold;">Request</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;txtID&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #990099; font-weight: bold;">Then</span>
        <span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;รหัสถูกต้องครับ&quot;</span>
    <span style="color: #990099; font-weight: bold;">Else</span>
        <span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;รหัสที่คุณกรอกไม่ถูกต้องครับ&quot;</span>
    <span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>จริงๆ แล้วถ้าเพื่อนๆ จะเอาไปใช้จริง ก็ Copy ไปเฉพาะฟังก์ชัน CheckID ก็ได้ครับ โดยพารามิเตอร์ตัวแรกของ CheckID ทั้ง 3 ภาษานี้คือ ข้อความที่เก็บรหัสประจำตัวประชาชนไว้ครับ<br />
ฟังก์ชันนี้จะคืนค่าเป็น True ถ้ารหัสถูกต้อง และคืนค่าเป็น False ถ้ารหัสผิดครับ</p>
<h3>สรุป</h3>
<p>เราได้เรียนรู้วิธีการตรวจสอบเบื้องต้น (ข้อย้ำว่าเบื้องต้น) เพราะรหัสประชาชนที่ผู้ใช้กรอก อาจมี Check Digit ที่ถูกต้อง แต่อาจเป็นรหัสประชาชนที่ไม่มีอยู่จริงก็ได้นะครับ<br />
<script type="text/javascript"><!--
google_ad_client = "pub-5366864020460148";
/* 468x60, created 7/22/09 */
google_ad_slot = "1450819552";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://nattster.siamdev.net/2006/09/id-verification/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

