Skip to main content
lindac61754001
Participant
November 24, 2018
Question

How do I create an if statement alert for a dropdown where the validation is: must be 12 characters and start with 25, 35, or 45?

  • November 24, 2018
  • 1 reply
  • 630 views

This is what I have so far however I do not know how to get the 35 and 45 in the statement.

I am using Adobe Pro XI. This is my first time adding scripts to document for validation.

event.rc = true;
if (event.value.length != 12 && event.value != 'Must be 12 digits Select Prefix and enter Account number behind. cheq -  25  ushceq  - 35  plan 24 - 45') {
    app.alert("The entered value must be 12 characters long and start with prefix cheq '25' or uscheq '35' or plan 24 '45'!");
event.rc = false;
}

var n = event.value.indexOf("25");

if (n == -1) { // substring not found
    app.alert("The entered value must be 12 characters long and start with prefix cheq '25' or uscheq '35' or plan 24 '45'");
    event.rc = false;
}
else {
    event.rc = true;

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
November 24, 2018

You can use the indexOf method that you're already using. It will return the index of the matching position for the term you're searching for. If it appears at the start of the string that will be 0.

Also, I would recommend you allow the event.value.length to be 0, or the user won't be able to clear the field...

lindac61754001
Participant
November 24, 2018

If I leave the script with event,value.indexOF("25") and try to enter 451234567898 to make it 12 characters and starts with 45 I am getting the pop up alert and it is correct it starts with 45 and 12 digits. If I enter 12 digits starting with 25 it works. How do I get it to validate the 35 and 45?  Also I need it to validate it is 12 digits, if I change the event,value.length to 0 it allows for more or less than 12 digits.

event.rc = true;
if (event.value.length != 12 && event.value != 'Must be 12 digits Select Prefix and enter Account number behind. cheq -  25  ushceq  - 35  plan 24 - 45') {
    app.alert("The entered value must be 12 characters long and start with prefix cheq '25' or uscheq '35' or plan 24 '45'!");
event.rc = false;
}

var n = event.value.indexOf("25");
if (n == -1) { // substring not found
    app.alert("The entered value must be 12 characters long and start with prefix cheq '25' or uscheq '35' or plan 24 '45'");
    event.rc = false;
}
else {
    event.rc = true;
}

pixxxelschubser
Community Expert
Community Expert
November 24, 2018

This is not specific for Acrobat - but it does what you want.

var prmt = prompt ("12 digits (start with 25, 35 or 45)", 253456789012, "check Number");

if (prmt.length != 12) {

    alert ("The entered value must be 12 characters long");

    }

if (prmt.match ( /^[234]5/ ) == null ) {

    alert ("""The entered value must be 12 characters long and start with prefix cheq '25' or uscheq '35' or plan 24 '45'""");

    };

Have fun