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

#   Custom field regular expression or blank

##

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

Less More

- Posts: 116
- Thank you received: 7
-

8 years 11 months ago -  8 years 11 months ago [\#283345](#283345) by [stratacorps](/forum/user/33546-stratacorps "View stratacorps's Profile")  *[Custom field regular expression or blank](/forum/33-customers/892951-custom-field-regular-expression-or-blank#283345 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2 -- PHP version -- : 7.0  I believe I am correct in saying that the regular expression check is not performed unless the custom field is set to Required.  The problem is that we want to do both..have optional fields, but make sure that they are formatted properly or left blank.  I have as an example the regular expression: (^&#92;D?(&#92;d{3})&#92;D?&#92;D?(&#92;d{3})&#92;D?(&#92;d{4})$)|^$  This will validate a properly formatted number (for US) or blank. But we can't get past the restrictions of the default behavior. We need either a properly formatted input, or nothing at all.  Is this possible with a work-around?  &#42;&#42;&#42;EDIT: I just found conditional field options...so I created an input for SMS Notifications and then made the mobile number with the regex conditional on that...so its a temporary work around. It would be cool though to be able to format input on optional fields ;) &#42;&#42;&#42;  Thank you!")* was created by *[stratacorps](/forum/user/33546-stratacorps "View stratacorps's Profile")*

-- HikaShop version -- : 3.2.1
-- Joomla version -- : 3.8.2
-- PHP version -- : 7.0

I believe I am correct in saying that the regular expression check is not performed unless the custom field is set to Required.

The problem is that we want to do both..have optional fields, but make sure that they are formatted properly or left blank.

I have as an example the regular expression: (^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$)&#124;^$

This will validate a properly formatted number (for US) or blank. But we can't get past the restrictions of the default behavior. We need either a properly formatted input, or nothing at all.

Is this possible with a work-around?

***EDIT: I just found conditional field options...so I created an input for SMS Notifications and then made the mobile number with the regex conditional on that...so its a temporary work around. It would be cool though to be able to format input on optional fields ![;)](/media/kunena/emoticons/11.png ";)") ***

Thank you!

Last edit: 8 years 11 months ago by [stratacorps](/forum/user/33546-stratacorps "View stratacorps's Profile"). Reason: Work around

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy84OTI5NTEtY3VzdG9tLWZpZWxkLXJlZ3VsYXItZXhwcmVzc2lvbi1vci1ibGFuaz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) 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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86295
- Thank you received: 14273
-
-

8 years 11 months ago [\#283375](#283375) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom field regular expression or blank](/forum/33-customers/892951-custom-field-regular-expression-or-blank#283375 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2 -- PHP version -- : 7.0  I believe I am correct in saying that the regular expression check is not performed unless the custom field is set to Required.  The problem is that we want to do both..have optional fields, but make sure that they are formatted properly or left blank.  I have as an example the regular expression: (^&#92;D?(&#92;d{3})&#92;D?&#92;D?(&#92;d{3})&#92;D?(&#92;d{4})$)|^$  This will validate a properly formatted number (for US) or blank. But we can't get past the restrictions of the default behavior. We need either a properly formatted input, or nothing at all.  Is this possible with a work-around?  &#42;&#42;&#42;EDIT: I just found conditional field options...so I created an input for SMS Notifications and then made the mobile number with the regex conditional on that...so its a temporary work around. It would be cool though to be able to format input on optional fields ;) &#42;&#42;&#42;  Thank you!")*

Hi,

That's right, only required custom fields will have the regex check enforced because of the way the system was done.
There are several ays to circumvent that limitation.
With another field and the "display limited to" setting, like you found, or your on custom field type, or with a custom plugin implementing the triggers for the type API you're using the custom field (product, order, etc).
The simplest is the workaround you found.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy84OTI5NTEtY3VzdG9tLWZpZWxkLXJlZ3VsYXItZXhwcmVzc2lvbi1vci1ibGFuaz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) 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.110 seconds

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

[](#top)
