Using Javascript to validate South African ID Numbers

I have just finished a neat little client side ID number validation script that ensures that the ID number passed is:

  • Numeric,
  • is 13 Digits long,
  • has a valid date with the first 6 characters
  • and passes the Luhn algorithm test.
function ValidateIDnumber(idnumber) {
//1. numeric and 13 digits
if (isNaN(idnumber) || (idnumber.length != 13)) { return false; }
//2. first 6 numbers is a valid date
var tempDate = new Date(idnumber.substring(0, 2), idnumber.substring(2, 4) - 1, idnumber.substring(4, 6));
if (!((tempDate.getYear() == idnumber.substring(0, 2)) && (tempDate.getMonth() == idnumber.substring(2, 4) - 1) && (tempDate.getDate() == idnumber.substring(4, 6)))) { return false; }
//3. luhn formula
var tempTotal = 0; var checkSum = 0; var multiplier = 1;
for (var i = 0; i < 13; ++i) {
tempTotal = parseInt(idnumber.charAt(i)) * multiplier;
if (tempTotal > 9) { tempTotal = parseInt(tempTotal.toString().charAt(0)) + parseInt(tempTotal.toString().charAt(1)); }
checkSum = checkSum + tempTotal;
multiplier = (multiplier % 2 == 0) ? 1 : 2;
}
if ((checkSum % 10) == 0) { return true };
return false;
}

Selecting all today’s records

Dates can be difficult to work with especially when you are not interested in the time portion. So here’s a quick snippet that strips the time portion out of the equation, making it easy to get only today’s records (or any day for that matter).

SELECT Column1,Column2, Datestamp FROM tblExample
WHERE DATEADD(day, DATEDIFF(day, 0, GetDate()), 0) = DATEADD(day, DATEDIFF(day, 0, Datestamp), 0)

Fantastic use of pure css to create animation

I like to think I have a fairly good grip on CSS, but this takes it to another level:
Introducing the rolling coke can…

Consider yourself humbled.

Hitler finds out about the new iPad

I’m a day late with this, but it is pretty funny stuff.

There are loads of rip off ads and video around already – check out a classic on cherryflava.

I still want one though…

Making Magento catalog price rules stick.

Magento

Magento

I am involved in an ecommerce venture that uses magento commerce to manage sales. For months I have been bugged by the fact that catalog price rules do not stick – you run the rule from the admin system; all looks great on the site; discounts are applied, but a day later the rule has stopped working and has to be applied again. Very frustrating and not cool.

The good news is I have eventually found a fix to the problem. Basically you need to update near the bottom of the cron.php file to read as follows:

try {
Mage::getConfig()->init()->loadEventObservers(’crontab’);
Mage::app()->addEventArea(’crontab’);
Mage::dispatchEvent(’default’);
$ob = Mage::getModel(’catalogrule/observer’);
$ob->dailyCatalogUpdate(“0 1 * * *”);

Once this is in place you can browse the cron.php file directly and take a deep sigh of relief.

I am still skeptical whether or not the cron job that I set up is actually going to kick this off automatically. Time will tell. I see though that if it does not work, there are services out there that will run a page on your site at specified intervals.

Holding thumbs.

A really really flexible CSS layout

This is a really really flexible layout that does not make use of tables and can be used as either a 1,2 or 3 column layout by simply including or omitting the left and right columns. The content is king, so the content comes first in the html followed by the rest. The structure is controlled via CSS with a little bit of coolness added on thanks to jQuery.

The top banner code is there only to show what is possible, the reason I built this was to have one template that could handle any layout. The interesting thing about the top banner though is that there are two background images on top of each other which creates a lot or flexibility when it comes to banner imagery that overlaps the extents of the 960 by x height banner area.

I have used one jQuery plugin to force equal height columns (1kb) and made use of the cdn for the jquery source.  So this should be really quick as well as flexible.

Demo

Simple, accessible, standards based and validated Form

We all know that tables are evil and you run the risk of being seriously uncool if you are caught using them. But when it comes to forms they really make cross browser layouts that much easier, which is why there are so many forms that use tables. In the interest of good standards based design I have created a form based on fieldsets and definition lists.

There are actually a few points to mention:

  • Definition lists are used to layout name/value pairs,
  • jquery validation modified from this article,
  • a conditional stylesheet has been used to please that other browser,
  • the sliding doors technique has been used to style the submit button,
  • Eric Meyer’s css reset was used to initialise defaults across browsers,
  • Required fields denoted by a star just by adding a class to the dt tag.

This form has been tested in all the major browsers: ie6+, firefox and chrome.

The Demo

Adding your Twitter timeline to Google Reader

Free My Feed

Free My Feed

Have you ever tried to add your twitter timeline to google reader and failed because it requires authentication? Enter www.freemyfeed.com. They do promise not to store your username and password – use at your own risk ;)

Must .. work .. harder…

Alfa Romeo Giulietta 2010

Alfa Romeo Giulietta 2010

The all new Alfa Romeo Giulietta. it will probably be a really bad decision and spend loads of time in the workshop, but you just can’t help wanting one.

Awesome streaming music site

jukeflySo you wish you could hear that album before buying it, or would like to have an uber playlist for a party – enter JukeFly. I am so going to try hooking my laptop up to the sound system. You can create your own playlists or listen to someone else’s. This is such a winner, I have been waiting for something like this since Pandora stopped streaming music outside the states.