Remember me

custom pattern validation

1 year 1 month ago #1

  • P.Paolo's Avatar
  • P.Paolo
  • Posts: 22
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

1 year 1 month ago #2

  • Viacheslav's Avatar
  • Viacheslav
  • Posts: 28858
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

1 year 1 month ago #3

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