Skip to main content
Inspiring
Feb 5, 2025 10:06 AM UTC
Answered

Special characters validation issue

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;
}
}

 

Inspiring
Feb 5, 2025 10:40 AM UTC

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;
	}
}

4 replies

PDF Automation Station
Community Expert
Community Expert
Feb 5, 2025 10:42 AM UTC

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?

Translate
Przemyslaw33443682rriuAuthorCorrect answer
Inspiring
Feb 5, 2025 10:40 AM UTC

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;
	}
}
Translate
try67
Community Expert
Community Expert
Feb 5, 2025 2:02 PM UTC

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ąĄćĆńŃżŻźŻśŚłŁęĘóÓ]/

Translate
try67
Community Expert
Community Expert
Feb 5, 2025 2:03 PM UTC

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

Translate