Magento: Limit the address fields to n characters

Mar 21, 2011


There are a number of reasons you may want to do this – but primarily I think it is because your despatch system will likely be printing labels and if the lines are too long it won’t work properly. You could try dealing with the line lengths when you export but that leaves you with the messy situations of trying to work out where to put the bits of the address yo uhave chopped off. My prefered approach is just to limit the fields on the front-end using your standard HTML maxlength attribute. Not perefect, but I think adequate since this is unlikely to happen frequently.

To do this you need to edit the relevant templates and simply insert the maxlength attribute. You should be editing the following files…


You should be able to spot the relevant input elements that you need to change, likely to be “shipping:street1”, “shipping:streetX”, “shipping:city” and “shipping:region_id” – where the X is the street address line number (because you can vary that in the admin).