Skip to main content
ZombieLuna
Inspiring
March 14, 2019
Answered

Text Field Cannot Allow Specific Words, Clear When Incorrect

  • March 14, 2019
  • 1 reply
  • 1328 views

I have a text field ("Weeks") that I do not want to allow users to input 'Points', 'Pts', or 'pts' and I want it to clear the text when it falls into these parameters.

I borrowed another code that I used to ensure a number was always negative and it worked - cleared the field when the word was input and everything:

event.rc = (event.value != "Points");

event.rc = true;

if (event.value == "Points") {

    app.alert("This field must be a week number or Float");

    event.rc = false;

}

Then, in my searchings, I tried to incorporate additional statements to make the code work for all three instances:

event.rc = (event.value != "Points" && event.value != "Pts" && event.value != "pts");

event.rc = true;

if (event.value == "Points" && event.value == "Pts" && event.value == "pts")

{

    app.alert("This field must be a week number or Float");

    event.rc = false;

}

But this did NOT work.  Stopped clearing the field, stopped showing the alert...allows the text to be input without any notification that anything is wrong.

I know I'm doing something wrong...or something that can't be done maybe...?  But I don't know how to fix it or how to go about finding out how to fix it.  Any help would be much appreciated!

This topic has been closed for replies.
Correct answer try67

I just realized I didn't answer the first part of your question either...  The field should NOT contain those values at all.  I'm including all three because our users will fill it in with the full word, abbreviated with a capital, AND with a lower case.  So I want to put restrictions in that prevent them all.


Yes, you didn't really answer my question, and it seems my assumption was incorrect.
So use this code, instead:

if (/points/i.test(event.value) || /pts/i.test(event.value)) {

    app.alert("This field must be a week number or Float");

    event.rc = false;

}

1 reply

try67
Community Expert
Community Expert
March 14, 2019

Should the field not be equal to those values (exactly), or should it not contain them at all?

For example, can the user enter "5 Points"?

ZombieLuna
Inspiring
March 14, 2019

The field is specific to a week number of the year (25 or 25, 26) or Float, which indicates that the unit can be used any week in the year that there is availability at the resort.

Points is a reference to the unit size that any owner has available to them, there is a specific place elsewhere in the document for that to be input.

ZombieLuna
Inspiring
March 14, 2019

I just realized I didn't answer the first part of your question either...  The field should NOT contain those values at all.  I'm including all three because our users will fill it in with the full word, abbreviated with a capital, AND with a lower case.  So I want to put restrictions in that prevent them all.