Copy link to clipboard
Copied
I'm hoping someone can me clean up the following Arbitrary Mask javascript I'd like to use on a form. My goal is to change it to just 3 alphabet letters. I can't seem to get the script right. Here is where i'm at with this and it's not working.
if(event.willCommit){
var input = event.value;
var pattern = /^(|\[A-Za-z]{3}$|$/);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}}
Thank you in advance for any ideas on how to make this work!
Copy link to clipboard
Copied
You don't need JavaScript to do this:
Copy link to clipboard
Copied
Use this:
var pattern = /^[a-z]{3}$/i);
Copy link to clipboard
Copied
Here is what i input and it did not work.
if(event.willCommit){
var input = event.value;
var pattern = /^[a-z]{3}$/i);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}}
Copy link to clipboard
Copied
Where did you place it? Under which event?
Copy link to clipboard
Copied
Right after event value. I made the text blue below to show you.
if(event.willCommit){
var input = event.value;
var pattern = /^[a-z]{3}$/i);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}}
Copy link to clipboard
Copied
No, the full code. Where did you place it under the field? Format? Keystroke? Validation? Something else?
Copy link to clipboard
Copied
Oh. I was trying to place it in the format, custom, custom keystroke but it was taking it.
Copy link to clipboard
Copied
Use just this part as the custom Validation script:
var input = event.value;
var pattern = /^[a-z]{3}$/i);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}
Copy link to clipboard
Copied
First of all, i really appreciate you helping me!
I entered in as a validation script and i got a SyntaxErro: missing : before statement 2: at line 3
Copy link to clipboard
Copied
I was playing around with this, looking at some things you've done for others and I came up with this as a custom validation script. I think this might work. I also included a pop up for the user instructing them to enter 3 letters. This is the best i could come up with.
if (event.value!="") event.rc = /^[a-z]{3}$/i.test(event.value);
Copy link to clipboard
Copied
You don't need JavaScript to do this:
Copy link to clipboard
Copied
Yes! This is the answer and THANK YOU!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now