I want to check if Field1 is in the format of XXXX-0YYYY or XXXX-1YYYY where XXXX are letters only and YYYY are digits only note that after XXXX it should start with "-0" or "-1" only
I made the following code and it didn't work as expected:
var string = this.getField("Field1").value;
var string1 = string.substring(0, 4);
var string2 = string.substring(5, 10);
var n1 = event.value.indexOf("-0",4);
var n2 = event.value.indexOf("-1",4);
var n3 = n1 + n2
var isLetter = /[^a-zA-Z]/.test(string1);
var isNum = /^\d+$/.test(string2);
if ( !isLetter || n3 < -1 || !isNum ) { // incorrect format
app.alert("ERROR MESSAGE");
event.rc = false;
}
else {
event.rc = true;
}