Skip to main content
Participating Frequently
August 5, 2023
Question

Java script for text box

  • August 5, 2023
  • 1 reply
  • 397 views

Goodnight

I would like some help. I wanted a script that followed these conditions in specifies:

- It would be a normal text balloon that would only accept capital letters, with a maximum limit of 2 characters. That is, it would accept an "AA" or an "A", but not an "AAA".

- Second, in addition to this criterion, I would be able to put the following words in the balloon. They are: "N/A" and "n/a".

- Intuido is a balloon that only accepts these variables and issues an alert when it is violated, but I am not managing to create this script to accept only 2 characters, with the exception of "N/A" and "n/a".

This topic has been closed for replies.

1 reply

Participating Frequently
August 5, 2023

Here the code so far. It accepts only capital letters with up to 2 characters, but does not accept "N/A" and "n/a" because it has 3 characters.

 

if (event.value) {
    if (event.value==" ") {
        app.alert("Quantity cannot be 0!", 0);
        event.rc = false;
    } else {
        event.rc = /^[A-Z, /, n, a]{1,2}?$/.test(event.value); 
        if (!event.rc) app.alert("Incorrect value!");
    }
}

try67
Community Expert
Community Expert
August 5, 2023

Try this:

 

if (event.value) {
    if (event.value==" ") {
        app.alert("Quantity cannot be 0!", 0);
        event.rc = false;
    } else if (event.value.toUpperCase()!="N/A" && /^[A-Z]{2}$/.test(event.value)==false) {
        app.alert("Incorrect value!");
        event.rc = false; 
    }
}

 

You don't really need the first part, though, as it's covered by the second one, but I left it there for you, just in case...