Huge Performance Improvements, CSS Units and More

Joomla Wesbite Builder Gridbox with Performance Improvements and CSS Units
Mon. - Fri. 9 am - 5 pm Ask a Question
Remember me

custom pattern validation

5 days 11 hours ago #1

  • P.Paolo's Avatar
  • P.Paolo
  • Posts: 19
Hi,
I need to add a custom pattern validation to a text input field in forms.
It's about a formal check on italian VAT number:
pattern = /^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$/
can you manage in some way?
BR
P.Paolo

5 days 8 hours ago #2

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 26073
Hello,
Thank you for contacting us

You need to add an input, type text, make it requested ,
add a custom class custom-vat-validation,
and add js in the code editor
document.addEventListener('DOMContentLoaded', () => {
	$f('.custom-vat-validation input[type="text"]').on('blur', function(){
		let match = /^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$/.test(this.value);
		if (!match) {
			this.value = '';
			formsApp.toggleAlertTooltip(!match, this, this.closest('.ba-field-container'), 'ENTER_VALID_VALUE');
		}
	});
})

Regards,
Vyacheslav, Balbooa.com

7 hours 31 minutes ago #3

  • P.Paolo's Avatar
  • P.Paolo
  • Posts: 19
Thank you!
Powered by Kunena Forum