cancel
Showing results for 
Search instead for 
Did you mean: 

Address line number validation on checkout / registering

Address line number validation on checkout / registering

Hi Folks,

 

I'm really no developer so I need your help in this Smiley Happy

Maybe it's very simple, but I can't get it to work.

 

What I'd like to achieve? A simple check if the addressline contains a number.

Some people forget to fill in their housenumber when checking out ... and in that case we can't send the product(s).

 

I thought it might be simple to use the built-in validation, in this case: 

'validate-number'               => 'Please enter a valid number in this field.'

So I edited this file:

app/design/frontend/ultimo/default/template/checkout/onepage/billing.phtml

 

 

<input type="text" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Street Address')) ?>" name="billing[street][]" id="billing:street1" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>" class="input-text validate-number <?php echo $_streetValidationClass ?>" />

As you can see I added the class validate-number ... but it isn't working. As I said, I might be looking in the wrong way here Smiley Tongue Hope you can help me figure it out Smiley Happy

1 REPLY 1

Re: Address line number validation on checkout / registering

How I like to resolve this, is by using two address lines instead of one. You can do this via System > Configuration > Customers > Customer Configuration. In the tab "Name and Address Options" you can set the value for "Number of Lines in a Street Address" to two. With some styling, it should be a problem to place them next to each other in the page. Depending on the way addresses are written where you live, you can set the validate-number on the first or second address field. And make both of them required, so people have to fill in both fields.

 

An example of the code I use for this is this:

 

<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
<li class="fields fields-<?php echo $this->helper('customer/address')->getStreetLines(); ?>">
    <?php if(!$formHelper->isFieldHidden('street1')): ?>
        <div class="input-box-help field street1">
            <label for="billing:street1" class="required"><em>*</em><?php echo $this->__('Address 1') ?></label>
            <div class="input-box">
                <input type="text" title="<?php echo $this->__('Street Address') ?>" name="billing[street][0]" id="billing:street1" maxlength="35" value="<?php echo $this->escapeHtml($_address->getStreet(1)) ?>" class="input-text <?php echo $_streetValidationClass ?>" />
            </div>
        </div>
    <?php endif; ?>

    <?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
        <?php if($_i > 2) $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
        <div class="field street<?php echo $_i ?>">
            <label for="billing:street<?php echo $_i ?>"<?php if($_i < 3): ?> class="required"><em>*</em<?php endif; ?>><?php echo $this->__('Address '.$_i) ?></label>
            <div class="input-box input-box-help">
                <input type="text" title="<?php echo $this->__('Street Address %s', $_i) ?>" name="billing[street][<?php echo $_i - 1 ?>]" id="billing:street<?php echo $_i ?>" maxlength="10" value="<?php echo $this->escapeHtml($_address->getStreet($_i)) ?>" class="input-text validate-number <?php echo $_streetValidationClass ?>" />
</div> </div> <?php endfor; ?> </li>

Be aware that this code is customised, so it might not work out of the box for your installation.

If this response was helpful to you, consider giving kudos to this post.
If this response solved your problem, click accept as solution to help others solve this