Validating barcodes

Today I promoted a new component into ZF’s core.


You think it did already exist? Yes, and no. Let’s clearify a little bit.
The old implementation of Zend_Validate_Barcode did not work properly. It was fixed to EAN13 and UPCA and very limited.

I reworked it completly, added new features and a easy API.
It is now a base component for Zend_Barcode, a new component which provides you with the ability to print barcodes.

So what are the new features of Zend_Validate_Barcode?

  • Adapter support: Each barcode type is now an adapter. This means it is easy to add new barcodes, and you can also provide new barcode types yourself
  • 12 new standards: Now 12 new barcode standards are supported. So we have 14 types which you can work with. New ones will be added as they are needed. As we see no benefit of adding all 200 known standards at once, this may be the better way ;-)
  • Select checksum validation: You can now select if a checksum should be validated when your barcode gives one
  • Improved validation: The validation has been improved. A check for the used character tables has been added
  • Barcode types: Now also validation of 2D (or even 3D) types is possible

And as said, Zend_Validate_Barcode is the base for Zend_Barcode. This component, written by a good fellow of mine, allows to print barcodes for example within a PDF document, or within images.

So now you can make professional documents (including barcodes within the document).
This is really important for a invoice.

Enough for now… when you want to know more look into the manual. The validator works like all other validators. So you will not see any difference.

Have fun with Zend Framework

Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top

Task updates

5 weeks have passed since my last blog.

This does not mean that I am not active.
Normally it’s exactly the other way round… when I have time I am writing blogs, and when I am busy… well, you know ;-)

Still I felt that I should give you an short overview of my actual work. So here we go:

* I18n Webinar
Yes, you read correct. I am writing a webinar for I18n. We wanted to present it at 3rd December, but I did not find time to finish it for this date. It will be delayed about 2-3 weeks.

So I am preparing some I18n webinars… the first will cover Basics of I18n, usage and internals of translation. Its mainly for beginners and people who want to get knowledge on workflow and some internals. Of course it will also cover some examples.

When I am receive good responses on this webinar I will also cover other I18n themes.

* Zend_Filter_Boolean
I almost finished a new filter which converts any input to real boolean. Not just a simple boolean cast. You can configure it which inputs are converted and which not. It even recognises localized input like “yes”/”ja”/”si” and “no”/”nein”/”njet”
I hope it will get approved for ZF 1.10.

* Zend_Validate_Barcode
I completly reworked this validator. It supports now adapters and I added validation for 12 additional barcode types. It will be used by Zend_Barcode, a new component by Mickael. It is already finished and should be approved for ZF 1.10.

* Zend_View_Helper_Currency
I added a new view helper which works with Zend_Currency. It is also finished and waits for approvement.

Of course also several issues have been fixed and some minor improvements have been made.
And 5 new proposals are waiting for acceptance.

I think that’s enough for now. :-)
So have fun with Zend Framwork

Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top

CreditCard validation

And once again I have a new component for your convinience.

Zend_Validate_CreditCard is a component which can validate creditcards. When you are an expert ZF user then you may probably note that there was already a Zend_Validate_Ccnum validator. But it had severe security problems.

Ccnum validator did not accept several CreditCard numbers even they were correct. On the other side several numbers were accepted even if they were incorrect.

The reason for this problems were that Ccnum validated only if the given number was valid according to Luhn, but not if they are creditcard numbers.

Now when you need to validate creditcards let’s take a deeper look into this validator and what it can archive.

First let’s define which credit card institute you want to accept:

$valid = new Zend_Validate_CreditCard(Zend_Validate_CreditCard::VISA);

Giving no institute will accept all available institutes, and giving an array will accept everyone of the given institutes.

$valid = new Zend_Validate_CreditCard(

When you now have to validate a creditcard number the following checks will be made:

* First the length of the number will be checked… every institute uses different lengths for it’s numbers
* Then the prefix will be checked… every institute uses a worldwide unique prefix for it’s cards
* Then the number itself will be validated by calculating a checksum

This way you can easily be sure that you get only creditcards from those institutes you accept.

Looks quite good until now but still there are some things which can obvisiously not be checked by a offline validation. For example is there no way to validate if a creditcard has been marked as stolen, or if the creditcard is out of lifetime. Of course there is a date on the card itself, but there is no way to validate it offline, except of the date itself which is not really secure, but only a check for dumbs.

Still there are ways to get also these things validated. Almost all creditcard institutes provide online services which will do the above mentioned checks. But these services are not free and therefor not be added to this validator. But Zend_Validate_CreditCard can be coupled with external functions. So you could access such an API yourself and couple your method with Zend_Validate_CreditCard.

class MyClass
    public function MyCheck($creditcard)
        // Do some online checks with the institutes API
        return true | false;
$valid = new Zend_Validate_CreditCard(Zend_Validate_CreditCard::VISA);
$valid->setService(array('MyClass', 'MyCheck'));

This way you could also attach your own validation methods. For example when you have a database with known numbers you would not accept, then you could add a method which does this check additionally to the existing validations.

Note that for performance reasons the connected service will only be called when all other offline validations are ok and valid. This prevents the call for numbers which are obisiously broken.

Have fun with this new component and of course with Zend Framework.

Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top