Skip to main content
Inspiring
February 5, 2025
Answered

Special characters validation issue

  • February 5, 2025
  • 2 replies
  • 625 views

Hi, in my Acrobat form I'm using script below to validate if user type minimum one character or number in field. If user type first Polish special character (ex. ą, ć, ę, ł, ó, ń, ż, ź) script show error alert.
How to avoid issue with special characters (or edit script that not the first character must be letter or number but field must contain minimum one character or number)?

 

if (event.value) {
if (/^[a-z,A-Z,0-9]*$/.test(event.value)==false) {
app.alert("Insert letter or number");
event.rc = false;
this.getField("name").required = true;
}else{
this.getField("name").required = false;
}
}

 

Correct answer Przemyslaw33443682rriu

I fixed it, topic close

if (event.value) {
	if (/^[a-z,A-Z,0-9,ą,Ą,ć,Ć,ń,Ń,ż,Ż,ź,Ż,ś,Ś,ł,Ł,ę,Ę,ó,Ó]/.test(event.value)==false) {
		app.alert("Wprowadź znak będący literą lub cyfrą");
		event.rc = false;
		this.getField("Imię").required = true;
	}else{
	this.getField("Imię").required = false;
	}
}

2 replies

PDF Automation Station
Community Expert
Community Expert
February 5, 2025

What is this script supposed to do? The first test is whether the field contains a value.  Any character typed will be minimum of 1.  Are you trying to alert the user if only a space is typed?

Przemyslaw33443682rriuAuthorCorrect answer
Inspiring
February 5, 2025

I fixed it, topic close

if (event.value) {
	if (/^[a-z,A-Z,0-9,ą,Ą,ć,Ć,ń,Ń,ż,Ż,ź,Ż,ś,Ś,ł,Ł,ę,Ę,ó,Ó]/.test(event.value)==false) {
		app.alert("Wprowadź znak będący literą lub cyfrą");
		event.rc = false;
		this.getField("Imię").required = true;
	}else{
	this.getField("Imię").required = false;
	}
}
try67
Community Expert
Community Expert
February 5, 2025

Be aware the commas you included in the list of characters are not needed, and in fact will cause the comma symbol to be accepted, which might not be desired. You can use this instead:

/^[a-zA-Z0-9ąĄćĆńŃżŻźŻśŚłŁęĘóÓ]/

try67
Community Expert
Community Expert
February 5, 2025

Also, if you add the "i" flag at the end you won't need to include the upper-case letters and your RegExp will be much simpler:

/^[a-z0-9ąćńżźśłęó]/i