regex validations

  • Posts: 126
  • Thank you received: 2
13 years 8 months ago #15500

Hello,

I'm looking for a way to add some validations to custom fields. For example, i need that phone number field to have 9 characters: /^[0-9]{9}$/ (format 723456789).

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

  • Posts: 83103
  • Thank you received: 13417
  • MODERATOR
13 years 8 months ago #15505

Hi,

What you can do is override the hikashopCheckChangeForm javascript function located in media/com_hikashop/js/hikashop.js in a js file of your template loaded AFTER that file and change the regex in it so that it checks for the number of characters.

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

  • Posts: 126
  • Thank you received: 2
13 years 8 months ago #15595

Can be done in an easy way? :) For example, another box for each field where i can add some validations (like fabrik component for example)?

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

  • Posts: 83103
  • Thank you received: 13417
  • MODERATOR
13 years 8 months ago #15596

It would be nice indeed. We can add that as a feature request. However, it's not possible on the current version where only the solution above is.

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

  • Posts: 27
  • Thank you received: 0
12 years 10 months ago #43176

Thanks for that info, works great for phone and other validation you already built for, but what about custom fields?
I have an address password custom field, that should only take numbers.
I have changed the phone filter validation and added some code to the if(type=='address') element like this:

else if(type=='address'){
			if(typeof varform.elements['data[address][address_telephone]'] != 'undefined'){
				var phoneField = varform.elements['data[address][address_telephone]'];
				if(phoneField){
					phoneField.value = phoneField.value.replace(/ /g,"");
					if(phoneField.value.length > 0){
						var filter = /^[0-9]+$/i;
						if( !filter.test(phoneField.value)){
							 alert(hikashop['valid_phone']);
					         return false;
						}
					}
				}
			}
			//added code for address password validation 
			else if(typeof varform.elements['data[address][address_password]'] != 'undefined'){
				var codeField = varform.elements['data[address][address_password]'];
				var filter = /^[0-9]+$/i;
				if( !filter.test(codeField.value)){
					 alert(hikashop['valid_code']);
			         return false;
				}
			}
		}

but this code doesn't work for me.
could you please help on that?
Thanks.

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

  • Posts: 27
  • Thank you received: 0
12 years 10 months ago #43179

never mind, silly me, just removed the else from my statement and left only the if syntax and it's working...
would love to know how to implement this hikashop); in my language file...

Last edit: 12 years 10 months ago by justaguy.

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

  • Posts: 83103
  • Thank you received: 13417
  • MODERATOR
12 years 10 months ago #43301

What you should do is set an error message in your custom field options.
Then, you can use joomfish/falang to translate the custom field error message.
Finally, in your code, you can use instead:
hikashop

which will contain the error message of the field address_password.

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

Time to create page: 0.087 seconds
Powered by Kunena Forum