Custom Field - Regex Validation

  • Posts: 106
  • Thank you received: 5
  • Hikaserial Standard Hikashop Business
9 years 5 months ago #202745

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.4.39

It would be great if we were able to add a custom text field and be able to apply regex validation. Just making the field required doesn't prevent the customer from entering incorrect information.

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

  • Posts: 82721
  • Thank you received: 13338
  • MODERATOR
9 years 5 months ago #202758

Hi,

That's a good idea. We'll look at adding that capability.

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

  • Posts: 106
  • Thank you received: 5
  • Hikaserial Standard Hikashop Business
9 years 4 months ago #204408

I appreciate you adding in this capability with 2.5.0, however, I cannot get it to work. I changed my custom field from Text to Custom Text, put in the regex and saved. Now there is no textbox for the customer to enter a value into and the product cannot be added to the shopping cart. Only the field label and the asterisk is shown. I cannot even revert the field back to Text, as that dropdown is not shown anymore for that field.

EDIT: Actually the product was added to the cart, but there was not the usual add to cart notice. There was also no warning about an invalid entry. Since there is no textbox, and thus no value entered, I would have expected some validation error being shown, but there wasn't.

Last edit: 9 years 4 months ago by gpraceman.

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

  • Posts: 106
  • Thank you received: 5
  • Hikaserial Standard Hikashop Business
9 years 4 months ago #204430

OK, I've got the field back to a text entry, but I had to change the field type in the database. I have my regex entered, but the validation fails, even for a valid entry.

My regex is: /[A-Z]{4}[0-9]+-[A-Z0-9]{4}-[A-Z0-9]{5}-[A-Z0-9]{4}-[A-Z0-9]{4}/i

A value of XXXX14-123D-E1234-567T-435H should be accepted, but fails validation. I ran the regex through an online tester and the regex worked as expected.

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

  • Posts: 26150
  • Thank you received: 4026
  • MODERATOR
9 years 4 months ago #204460

Hi,

The regex will be processed by that javascript

myregexp = new RegExp(hikashopFieldsJs['regexValueFieldsComp'][type][found]);
if(myregexp.test(elementToCheck.value)){
	isValid = true;
}
which means that you have to specify your regex without delimiters (your "/") and without the flags (your "i").

Also, please make sure that your field is required or the regex check will be skipped.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Last edit: 9 years 4 months ago by nicolas.

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

  • Posts: 106
  • Thank you received: 5
  • Hikaserial Standard Hikashop Business
9 years 4 months ago #204508

Thanks, I got it working. It would be nice if when a new version is released if it included updated documentation. I see nothing about the regex feature in the current documentation.

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

  • Posts: 26150
  • Thank you received: 4026
  • MODERATOR
9 years 4 months ago #204511

Hi,

HikaShop 2.5.0 is release but the automatic update is not activated.
We should update the documentation after the "final" release of HikaShop 2.5

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Time to create page: 0.065 seconds
Powered by Kunena Forum