Jump to content

Zip code input validation


cqpbert

Recommended Posts

where can I put an input validation for the Zip code?

At least twice I have received orders with the persons email address in the zip code field. Now I get that the customer has entered this wrong, but seems like we should at least check there is no @ in the zipcode?

Link to comment
Share on other sites

The (jQuery-based) Validator code that the Foundation skin uses has an 'additional package' that can be incorporated. This package has several postcode tests, as well as a 'numbers, letters, and underscore only' test.

I will be experimenting with that soon.

 

Link to comment
Share on other sites

Go here and download the jquery.validator.additional-methods.js file:

https://github.com/jquery-validation/jquery-validation/tree/1.19.5/dist

Place the file in the skin's /js/vendor/ folder.

Edit the skin template element.js_foot.php file:

Find:

{assign var=js_foot value=[ 'skins/{$SKIN_FOLDER}/js/vendor/jquery.rating.min.js',
                            'skins/{$SKIN_FOLDER}/js/vendor/jquery.validate.js',

Add after:
                            'skins/{$SKIN_FOLDER}/js/vendor/jquery.validator.additional-methods.js',

Edit the skin's javascript 3.cubecart.validate.js file:

Near line 355, find:

    $("#addressbook_form").validate({
        rules: {

Then find:

            postcode: {
                required: true
            }

Change to:

            postcode: {
                alphanumeric: true,
                required: true
            }

Near line 214, find:

    $("#checkout_form").validate({
        rules: {

Then find:

            'billing[postcode]': {
                required: true
            },

Change to:

            'billing[postcode]': {
                alphanumeric: true,
                required: true
            },

Then find:

            'delivery[postcode]': {
                required: true
            },

Change to:

            'delivery[postcode]': {
                alphanumeric: true,
                required: true
            },

Log in to the storefront and view your addressbook. Edit an existing address. Change the postcode to have a character other than a letter, number, or underscore (not dashes or spaces). When the Save button is clicked, there should appear a red banner saying to use only certain characters.

The additional methods file include rules for various postal code formats: CA, NL, IT, UK, US. But I have yet to learn how to get the validator to cycle through them until one returns true, or to positively choose which one to use.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...