Skip to main content
Participating Frequently
June 23, 2023
Question

Convert Reg Ex to Javascript for Adobe Form

  • June 23, 2023
  • 2 replies
  • 713 views

Hello, 

I have a text field that I want to limit to AlphaNumeric and must be 7 characters
I currently have this under custom validation string to trigger it to be a required field based off of another field.
this.getField("Rebate Admin Fee 1").required = event.value == " " ? false : true;

 

I need to also add the 7 character rule to this section. the regex I would use is ^[a-zA-Z0-9]{7}$
How can I make this into a Javascript? and add it to the validation above?

Thank you in advance!

This topic has been closed for replies.

2 replies

Legend
June 23, 2023

Adjust the suggested script - with a regex for any number of alphanumeric characters - and replace the regex part with your original regex. The reply shows the principle of how to use a regex, so you can adapt it.

Legend
June 23, 2023

Sorry, I really seem not to have read all of your reply! Yes, what you've done looks right.

Participating Frequently
June 23, 2023

Thanks! I put event.rc = /^[a-zA-Z0-9]{7}$/.test(event.change);
within the keystroke script but it is not giving the required result, any idea what to change?

Nesa Nurani
Community Expert
Community Expert
June 23, 2023

In field properties under 'Options' tab, set character limit to 7 and under 'Format' tab ⇾ 'Custom' as 'Custom keystroke script' use this:

event.rc = /^[a-zA-Z0-9]*$/.test(event.change);

 

Participating Frequently
June 23, 2023

Thank you, I entered this under Format> Custom>Keystroke Script
It allows you to type Up To 7 Characters but it will still submit the form if there is 6 characters only. 
This field must contain 7 AlphaNumeric Characters to be valid. 

Is there a different area I should enter the above script? or should it be:
event.rc = /^[a-zA-Z0-9]{7}$/.test(event.change);

Thank you so much for your help!