The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

How to validade the tax id

Hi, i have enabled the tax id as mandatory on my shop, i would like to validade it. In Brazil all tax Ids named (CPF) can be validated using a function.

This is the CPE format in brazil: ###.###.###-## where # is replaced by a number.

Can the tax id field be validade at foxycart?

Thank you

  • fc_adamfc_adam FoxyCart Team

    Good question. We don't have any default validations as you've noticed, but it is possible to add in some custom validations and we have some example code for that which we worked up for another user that you could use.

    You'll want to jump into the FoxyCart administration and head to the configuration page. Look for the "Add custom header and footer code to your templates" option, and enable it if it's not already.

    Within that textarea, copy and paste the code shown at this link into the "footer" textarea:

    Look for this line in the script you just pasted:
    var taxIDRegex = /[a-zA-Z]{2}-[a-zA-Z0-9]\d{8}/;
    And update it to be this instead:
    var taxIDRegex = /\d{3}\.\d{3}\.\d{3}-\d{2}/;
    You'll also want to update the variable in the next line - changing the error message to match your specific format at least.

    If you then save the configuration, if you head to your checkout and enter a tax ID, it should validate your entry after leaving the field, or attempting to complete the checkout.
  • Hi @fc_adam, it did not worked, is not virifing, and now the field seams not to me madadory anymore.
  • fc_adamfc_adam FoxyCart Team
    edited January 2018

    Ah sorry - I forgot you weren't shipping anything, and because that script was assuming that there was shippable products, it was missing the tax ID on the billing fields.

    To correct that - look for the two instances of this string in the code: #shipping_tax_id, and replace it with this: [name^='_tax_id']. I've updated that string in the code on the original link if you want to reference how that looks in context, although it doesn't include the other modifications I mentioned earlier.

    That should get it working for you then. In terms of being required, from what I can tell on your checkout, that field is still being required for completing the checkout. Let me know if you are able to complete the checkout without filling it in though and we can take a closer look.
  • Thanks a lot! Working perfeclty!
Sign In or Register to comment.