java script problems with input mask
<p>In my form where i use JavaScript when I enter 6 digit postal code in box in submit form then city is automatically update If i providing incomplete pin code and clicking outside Postal Box in form data is cleared.</p>

<p>I want data not cleared if i enter incomplete postal code.how it is possible?</p>

<p>JavaScript File:</p>

<pre><code>BRAPRINT.frontend.main = function() {

var $ = jQuery;
var self = {};

function resolvePostalCode() {
    var inputName = this.attr('id');
    var postalCode = this.val();

    var baseName =
        inputName.substring(0, inputName.lastIndexOf('_'));

    var isBilling = baseName.match(/billing/gi);
    var isShipping = baseName.match(/shipping/gi);

    var completeCallback = function(result) {
        $('#'+ baseName +'_postalCode + img').remove();
        $('#'+ baseName +'_postalCode').parent().find('ul').remove();

        if (result.success) {
            var data = result.data;

            //$('#'+ baseName +'_streetAddress').val(data.street);
            //$('#'+ baseName +'_neighborhood').val(data.neighborhood);
            $('#'+ baseName +'_municipality').val(data.city);
            $('#'+ baseName +'_addressRegion').val(data.regionId);
            $('#'+ baseName +'_postalCode').parent().find('div').remove();

        } else {
            $('#'+ baseName +'_postalCode').parent().find('div').remove();
            $('#'+ baseName +'_postalCode').after('&lt;div class="form_help"&gt;Not in shipping coverage. Agent will contact you.&lt;/div&gt;');
        }

        if (isShipping &amp;&amp; typeof self.shippingAddressResolveCallback !== 'undefined') {
            self.shippingAddressResolveCallback(postalCode, data);
        }

        if (isBilling &amp;&amp; typeof self.billingAddressResolveCallback !== 'undefined') {
            self.billingAddressResolveCallback(postalCode, data);
        }
    };

    this.after('&lt;img src="/bundles/frontend/img/ajax-loader.gif"/&gt;');

    $.ajax({
        'url': '/postalcode/resolve/' + this.val().replace('-', ''),
        'dataType': 'json',
        'type': 'get',

        'success': completeCallback
    });
}

function applyInputMasks() {
    var $form = $('form');

    if ($form.size()) {
        // added try catch so that if input field not found then it wont give an error
        try{
            //$form.find('input:not([skip-masks])[name*=cpf]').mask("999.999.999-99");
            //$form.find('input:not([skip-masks])[name*=document]').mask("999.999.999-99");
            $form.find('input:not([skip-masks])[name*=date]').mask("99/99/9999");
            $form.find('input:not([skip-masks])[name*=postalCode]').mask("999999");
            //$form.find('input:not([skip-masks])[name*=phone]').mask("999999999999");

            // Postal code
            var $postalCode = $form.find('input:not([skip-masks])[name*=postalCode]');

            if ($postalCode.attr('skip-resolve-postalcode')) {
                $postalCode.mask("999999");
            } else {
                $postalCode.mask("999999");
                $postalCode.mask("999999", {completed: resolvePostalCode});
            }

            // override the value AFTER applying the mask
            var valueToOverride = $postalCode.attr('override-value');
            if (valueToOverride) {
                $postalCode.val(valueToOverride);
            }
        } catch (e) {}
    }

    BRAPRINT.util.log('Masks applied!');
}
</code></pre>
