<?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>LogikDevelopment &#187; EAN barcode</title>
	<atom:link href="http://www.logikdev.com/tag/ean-barcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.logikdev.com</link>
	<description>&#34;Il n&#039;y a pas de problème, il n&#039;y a que des solutions. L&#039;esprit de l&#039;homme invente ensuite le problème.&#34; André Gide</description>
	<lastBuildDate>Tue, 20 Dec 2011 12:25:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Validate your EAN barcode</title>
		<link>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=validate-your-ean-barcode</link>
		<comments>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/#comments</comments>
		<pubDate>Thu, 13 May 2010 21:04:33 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[EAN barcode]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=520</guid>
		<description><![CDATA[On one of the applications I am working on, I had to validate an EAN (European Article Number) barcode. This application is mostly using JavaScript validation so I asked my friend Google to find me a JavaScript method which would check my EAN barcode. It found validators in different languages but none in JavaScript. Because [...]]]></description>
			<content:encoded><![CDATA[<p>On one of the applications I am working on, I had to validate an EAN (<a target="_blank" href="http://en.wikipedia.org/wiki/European_Article_Number">European Article Number</a>) barcode.<br />
This application is mostly using JavaScript validation so I asked my friend Google to find me a JavaScript method which would check my EAN barcode.<br />
It found validators in different languages but none in JavaScript. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Because one is never better served than by oneself, I decided to write it myself and share it with you. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre class="brush: jscript; title: ; notranslate">
function checkEan(eanCode) {
	// Check if only digits
	var ValidChars = &quot;0123456789&quot;;
	for (i = 0; i &lt; eanCode.length; i++) {
		digit = eanCode.charAt(i);
		if (ValidChars.indexOf(digit) == -1) {
			return false;
		}
	}

	// Add five 0 if the code has only 8 digits
	if (eanCode.length == 8 ) {
		eanCode = &quot;00000&quot; + eanCode;
	}
	// Check for 13 digits otherwise
	else if (eanCode.length != 13) {
		return false;
	}

	// Get the check number
	originalCheck = eanCode.substring(eanCode.length - 1);
	eanCode = eanCode.substring(0, eanCode.length - 1);

	// Add even numbers together
	even = Number(eanCode.charAt(1)) +
	       Number(eanCode.charAt(3)) +
	       Number(eanCode.charAt(5)) +
	       Number(eanCode.charAt(7)) +
	       Number(eanCode.charAt(9)) +
	       Number(eanCode.charAt(11));
	// Multiply this result by 3
	even *= 3;

	// Add odd numbers together
	odd = Number(eanCode.charAt(0)) +
	      Number(eanCode.charAt(2)) +
	      Number(eanCode.charAt(4)) +
	      Number(eanCode.charAt(6)) +
	      Number(eanCode.charAt(8)) +
	      Number(eanCode.charAt(10));

	// Add two totals together
	total = even + odd;

	// Calculate the checksum
    // Divide total by 10 and store the remainder
    checksum = total % 10;
    // If result is not 0 then take away 10
    if (checksum != 0) {
        checksum = 10 - checksum;
    }

	// Return the result
	if (checksum != originalCheck) {
		return false;
	}

    return true;
}
</pre>
<p>Note that this code can validate EAN-8 and EAN-13 barcodes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

