Where do I have to add my regex code?

I want to make sure customers in my clients shop can only order within a particular postal code area. Everyone else will need to get an error.

I created a regex code to do that with research and help of a generator.

Now, since I have no clue about regex yet, I don’t know how and where to put the code.

I tried to add it to the custom attribute area, but it doesn’t work.

Here is my code: (1011[5-9]|101[2-9][0-9]|10[2-9][0-9]{2}|1[1-3][0-9]{3}|14[01][0-9]{2})

Can someone help me?

Thank you so much :slight_smile:

Here is my site Read-Only: LINK

Hello @Steffen_Schulz, so you need custom code to accomplish what you want. So you can try adding this code on your page settings before the /body tag:

    $(document).ready(function(e) {
        $('#btnSubmit').click(function() {
            var zipcode = $('#zipcode').val();
						var reg =(1011[5-9]|101[2-9][0-9]|10[2-9][0-9]{2}|1[1-3][0-9]{3}|14[01][0-9]{2});           
            if (reg.test(zipcode)) {
                return 0;
            } else {
                return false;

You will have to assign the submit button an id of btnSubmit, the zip code input field an id of zipcode, and create div-block with the error text and a class of errordiv with a display of none. You will have to test the code on a published site. I hope this helps.

1 Like

Thank you so much Pablo :pray: :slightly_smiling_face:

I am sure this will make it work. But I just recognized that I can’t try it out until my client will add the payment providers.

As soon as that happened, I will get back to you and tell you if it worked.

Have a great day and thank you again. :slight_smile:

1 Like