Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Java script for text box

Community Beginner ,
Aug 04, 2023 Aug 04, 2023

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".

TOPICS
How to
322
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2023 Aug 04, 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!");
    }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2023 Aug 05, 2023
LATEST

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines