Custom field regular expression or blank

  • Posts: 116
  • Thank you received: 7
  • Hikashop Business
6 years 4 months ago #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: (^\D?(\d{3})\D?\D?(\d{3})\D?(\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?

***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 ;) ***

Thank you!

Last edit: 6 years 4 months ago by stratacorps. Reason: Work around

Please Log in or Create an account to join the conversation.

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
6 years 4 months ago #283375

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 or Create an account to join the conversation.

Time to create page: 0.056 seconds
Powered by Kunena Forum