Skip to main content
Participant
May 23, 2022
Question

Acrobat Textbox Letter OR Number Validation

  • May 23, 2022
  • 2 replies
  • 1394 views

Any help would be a godsend - I've searched/played with this issue for a few weeks with no luck.

 

Acrobat obviously has built in validation/Format for numbers and specific text (e.g. Date). I am look for a javascript validation or custom format that allows the user to enter EITHER [a-zA-Z] OR [0-9], but not both. Not picky about further formatting.

 

The reason is that the form is calculating values, and I want users to be able to enter text notes in leui of numbers if necessary, but notes with numbers still calculate!

 

Thank you for any help. 

Sam 

This topic has been closed for replies.

2 replies

bebarth
Community Expert
Community Expert
May 23, 2022

Hi,

Instead of a validation script I suggest a custom keystroke script that allows only to type either one or the other one format:

if(!event.willCommit) {
	var aTester=event.value.split("");
	aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
	var testeChaine=aTester.join("");
	var modeleRegEx=/^([a-zA-Z]*|[0-9]*)$/;
	event.rc=modeleRegEx.test(testeChaine);
} else {
	var modeleRegEx=/^([a-zA-Z]*|[0-9]*)$/;
	event.rc=event.value=="" || modeleRegEx.test(event.value);
}

I think it's better to manage the keystroke than to check what was keystroked...

@+

Inspiring
May 23, 2022

What if number is decimal?

bebarth
Community Expert
Community Expert
May 23, 2022

That was not in the question, but if you need you can modify:

var modeleRegEx=/^([a-zA-Z]*|([0-9]*[.]?[0-9]*))$/;

Or if you want only 2 decimals:

var modeleRegEx=/^([a-zA-Z]*|([0-9]*[.]?[0-9]{0,2}))$/;

@+

Nesa Nurani
Community Expert
Community Expert
May 23, 2022

Try this as Validation script of that field:

var str = event.value;
var t = /^(?=.*[a-zA-Z])(?=.*[0-9])/.test(str);
if(t){
app.alert("Please enter correct format either text or number not both.");
event.rc = false;}

If you are using field in calculation you will need to adapt calculation script to not include it if it's a string.