This piece of code will separate out the account number and routing number from a scanned check. I yanked this function out of a payment class I wrote for a point of sale web application I recently developed. It’s a mootools class, but the core logic can be pulled out and applied pretty much anywhere.
- First pass a string into the function, where the string is the string from the check scan
- I immediately validate the information is correct. Scanners will send a series of question marks if the check was scanned in at an odd angle. They are very picky, but I tested many ways of sending the check through and this should catch most scenarios
- The routing number is stored between two “T” characters in the string. So I look for the T’s, remove them and store off the routing number
- The end of the accounting number has a “U” character immediately after it so and the account number starts immediately after the routing number, so I substring that out
- I then do some more error checking. Since both the account and routing number should be numeric I use isNan() to verify this.
- The entire snippet is wrapped in a try catch so should anything fail it can be logged and reported to the end user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| setCheckAttributes: function(string){
try{
if(string.charAt(0)=='?' || string.charAt(1)=='?' || string.charAt(1)=='?')
{
displayMessageWindow('Invalid Check','Please verify the check was scanned properly with the check facing in and the routing/account numers at the bottom','error');
return false;
}
var t1=string.search("T"); // start of routing number indentifier
string = string.replace("T","");
var t2=string.search("T"); // end of routing number indentifier, start of account number indentifier
this.routing = string.substring(t1,t2); // set routing number
var u=string.lastIndexOf("U"); // end of account number indentifier
var account = string.substring((t2+1),u);
var accountArr = account.split(" ");
this.account = accountArr.join(""); // set account number
if(isNaN(this.account) || isNaN(this.routing)){
this.account='';
this.routing='';
this.payment_method_id=0;
this.type='';
displayMessageWindow('Invalid Check','The system encountered an error reading the check and has invalid (non-numeric) information for either the routing or account number.','error');
return false;
}
return true;
}
catch(err){
pushToErrorLog('class Payment::setCheckAttributes() ' + err);
return false;
} |
To determine when a check has been scanned you can use the code in my post, JavaScript snippet for handling credit card readers.
This JavaScript function will successfully extract a credit card number, name of the card holder, and expiration date from any standard credit card reader. I’ve tested this on numerous card types from American Express to Visa and many in between. This function was originally a method within a MooTools class that I wrote for a web application. So it will look a little strange, but is easily modifiable if you know your way around JavaScript, especially if you have played around with any JavaScript framework. A typical string stored with in the magnetic strip of a credit card will look something like the string below. In this string you can see the card belongs to Jon Fubar, the credit card number is 123401230123012, and the expiration date is 01/09. It is not possible to extract the CVV from this string (good for security purposes).
Read the rest of this entry »
This is actually really simple and gives you some nice OOP functionality a web developer would not normally have in their web applications.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| var Customer = new Class({
initialize: function(firstName, lastName, address, address2, city, state, zip, phone, email){
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.address2 = address2;
this.city = city;
this.state = state;
this.zip = zip;
this.phone = phone;
this.email = email;
},
quickSet: function(){
this.firstName = $('firstName').value;
this.lastName = $('lastName').value;
this.address = $('address').value;
this.address2 = $('address2').value;
this.city = $('city').value;
this.state = $('state').value;
this.zip = $('zip').value;
this.phone = $('ph1').value+$('ph2').value+$('ph3').value;
this.email = $('email').value;
}
}); |
In this example initialize is the constructor, which is required for a mootools class, where quickSet is a method I created for this class.
I’ve been using MooTools MochaUI pretty extensively in building an intranet / administrative portal for a school. Unfortunately I have been unable to find a calendar that does not conflict with mocha on some level. We’ll finally a user on the mocha ui google group posted this calendar:
http://nsftools.com/tips/DatePickerTest.htm
It works great and can be made to look just as good as any of the mootools calendars through some simple CSS modifications.
1
2
3
4
5
6
| var tbl = document.getElementById('table');
var row = tbl.getElementById('tr');
var cell = row.getElementsByTagName('td');
cell[0].innerHTML='cell 0';
cell[1].innerHTML='cell 1';
cell[2].innerHTML='cell 2'; |
Checkout mochaUI I’ve been using it on a new web app I’m building and I’m very impressed with it. The code is very straightforward and the developers of mochaUI have put together some good documentation. It’s based on the MooTools javascript framework.
Creating slick interfaces can be as easy as this:
1
2
3
4
5
6
7
8
9
| document.mochaUI.newWindow({
id: 1,
title: 'Add Note',
content: 'some text is here',
scrollbars: true,
modal: false,
width: 400,
height: 200
}); |
This was posted to slashdot. I’d personally like to see Javascript get closer to C style languages as thats what I am most familiar with , the part that scares me though is backwards compatibility with ancient browsers. JavaScript is already a nightmare with browser compatibility.
http://blog.jeremymartin.name/2008/03/web-20-meet-javascript-20.html
In this article I gave a brief intro to using JSON to pass JavaScript arrays to PHP via Ajax. I’ve done a bit more with json since then and with the help of a co-worker discovered how to get javascript objects working together with php utilizing json.
Passing Multiple JavaScript objects to PHP
JavaScript class:
1
2
3
4
5
6
| function product(id,name,price)
{
this.id=id;
this.name=name;
this.price=price;
} |
Above we just create a simple javascript class that we will call below.
Putting JavaScript objects into JavaScript array:
1
2
| var object = new product('222','spectacular fizz','3.59')
var productsArr[productsArr.length] = object; |
We can now add as many of the these objects as we would like to the products array. So lets say we have an array that looks like this below…
1
2
3
| productsArr[0] = object...
productsArr[1] = object...
productsArr[2] = object... |
…and we want to pass it over to PHP. So we use the following code to turn it into a JSON string.
1
| var productsJSON = JSON.stringify(productsArr); |
Now we need to do an AJAX Post and on the PHP side we decode the JSON string (note you only need to stripcslashes if magic quotes its turned on):
1
| $productsArr = $this->json->decode(stripcslashes($productsJSON)); |
Now we can reference these objects multiple ways. One if we are just continuously looping through we can use a foreach:
1
2
3
4
5
6
| foreach($productsArr as $product)
{
echo $product->id;
echo $product->name;
echo $product->price;
} |
Or of course we can reference the object directly by its index in the array.
1
| echo $productsArr[1]->name; |
Pretty cool huh.
Pretty slick way for making a thumbnail viewer. This works in the following browsers: Safari (windows), FireFox 2 (windows), Internet Explorer 7, Internet Explorer 6, and Internet Explorer 5.5.
http://www.digitalia.be/software/slimbox
Needed to make a div element scrollable with no browser scroll bars in it and was unable to find any code. So I quickly threw together a proof of concept before developing for the client. Yes the initial “thing” I created is rather hideous, but the code is easy to modify and make pretty. View source to see the javascript code.
click here to view