Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You can add multiple such conditions in a single if-statement, like this:
if (event.value.indexOf("45")!=0 && event.value.indexOf("25")!=0) ...