[Skip to main content](#vessel-content)

#   How to use regular expression check to compare values of two custom fields?

##

- **[tonyhang](/forum/user/7979-tonyhang "View tonyhang's Profile")**
- [![tonyhang's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/7979-tonyhang "View tonyhang's Profile") Topic Author
- [ Offline](/forum/user/7979-tonyhang)

Less More

- Posts: 9
- Thank you received: 0
-

1 year 4 months ago [\#367523](#367523) by [tonyhang](/forum/user/7979-tonyhang "View tonyhang's Profile")  *[How to use regular expression check to compare values of two custom fields?](/forum/33-customers/909492-how-to-use-regular-expression-check-to-compare-values-of-two-custom-fields#367523 "Hi,  If there are two custom fields of Text type, address&#95;telephone1 and address&#95;telephone2. how can I use regular expression to check if the value of address&#95;telephone2 equals the value of address&#95;telephone1? I want to make sure users input the correct telephone number.  Thank you!")* was created by *[tonyhang](/forum/user/7979-tonyhang "View tonyhang's Profile")*

Hi,

If there are two custom fields of Text type, address_telephone1 and address_telephone2. how can I use regular expression to check if the value of
address_telephone2 equals the value of address_telephone1? I want to make sure users input the correct telephone number.

Thank you!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy85MDk0OTItaG93LXRvLXVzZS1yZWd1bGFyLWV4cHJlc3Npb24tY2hlY2stdG8tY29tcGFyZS12YWx1ZXMtb2YtdHdvLWN1c3RvbS1maWVsZHM/dG1wbD1tYXJrZG93bg==) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86322
- Thank you received: 14281
-
-

1 year 4 months ago [\#367524](#367524) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to use regular expression check to compare values of two custom fields?](/forum/33-customers/909492-how-to-use-regular-expression-check-to-compare-values-of-two-custom-fields#367524 "Hi,  If there are two custom fields of Text type, address&#95;telephone1 and address&#95;telephone2. how can I use regular expression to check if the value of address&#95;telephone2 equals the value of address&#95;telephone1? I want to make sure users input the correct telephone number.  Thank you!")*

Hi,

You can't do that with a regular expression check. A regular expression allows you to check the format of the value entered in a field. The regular expression doesn't have access to the value of other fields.

I'm afraid it will require some coding, one way or another.

One solution could be to:
- use the "display view files" setting of the HikaShop configuration to identify which view file(s) is used to display the fields :
[ www.hikashop.com/support/documentation/5...g.html#advanced\_main](https://www.hikashop.com/support/documentation/54-hikashop-config.html#advanced_main)
- edit the view file(s) via the menu Display&gt;Views.
- in there, add custom javascript code to make that check: Code:

&lt;span id="error-message" style="color: red; display: none;"&gt;Telephone numbers do not match.&lt;/span&gt; &lt;script&gt; document.addEventListener('DOMContentLoaded', function () { const tel1 = document.getElementById('address_telephone1'); const tel2 = document.getElementById('address_telephone2'); const errorMessage = document.getElementById('error-message'); function checkTelephoneMatch() { if (tel1.value &amp;&amp; tel2.value) { if (tel1.value !== tel2.value) { errorMessage.style.display = 'inline'; return false; } else { errorMessage.style.display = 'none'; return true; } } errorMessage.style.display = 'none'; return true; } // check on input change tel1.addEventListener('input', checkTelephoneMatch); tel2.addEventListener('input', checkTelephoneMatch); }); &lt;/script&gt;

Note that this is a simplified solution. I will only add a message to the user if the value in each field are not the same but it won't block the user from proceeding. A proper solution would also have to block the form submission where these fields are if they are not filled with the same text. So ideally, the code would have to be modified in each view file to adapt to the form there to handle that and it is not that simple.

A better solution, supposing that both fields are of the table "address", would be to implement the onBeforeAddressCreate and onBeforeAddressUpdate events of the HikaShop address API in a plugin of the group "hikashop":
[ www.hikashop.com/support/documentation/6...ntation.html#address](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#address)
In them, you could compare both fields in $element-&gt;address_telephone1 and $element-&gt;address_telephone2 and if different, set $do to false and add an error message with Joomla's error message system:
[ docs.joomla.org/display\_error\_messages\_and\_notices](https://docs.joomla.org/display_error_messages_and_notices)

This could help:
[ chatgpt.com/share/6843597c-b19c-8003-a3c3-8a84c7ea7fb2](https://chatgpt.com/share/6843597c-b19c-8003-a3c3-8a84c7ea7fb2)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy85MDk0OTItaG93LXRvLXVzZS1yZWd1bGFyLWV4cHJlc3Npb24tY2hlY2stdG8tY29tcGFyZS12YWx1ZXMtb2YtdHdvLWN1c3RvbS1maWVsZHM/dG1wbD1tYXJrZG93bg==) or [Create an account](/register) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.048 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
