11 Replies Latest reply on Aug 3, 2015 2:06 PM by jamie61880

    NEQ text string

    jamie61880 Level 1

      Hi. I have an If statement to see if N/A or NA is in a text box. If it is, I don't want to send an automated email I have set up. This works great if only N/A or NA is in the text box, but what if someone writes something like "N/A This component does not work for this part." How do I test this if the text box starts with N/A or NA and has text after it still? Here's my If Statement:

       

      <cfif isDefined("form.Open_Jobs_Affected#id#") and evaluate("form.Open_Jobs_Affected#id#") neq "N/A" and evaluate("form.Open_Jobs_Affected#id#") neq "NA">

       

      Thanks for your help.

      Andy

        • 1. Re: NEQ text string
          nic_tunney Adobe Community Professional

          A regular expression would probably do what you need.  Something similar to this:

           

          <cfif isDefined(myField) and NOT REFindNoCase("^NA", myField) and NOT REFindNoCase("^N\/A", myField)>

          ...

          • 2. Re: NEQ text string
            jamie61880 Level 1

            Nic,

                This almost worked perfectly! The only problem is if I type in Nano Socket, it looks at the Na and thinks it shouldn't send an email, but it should. It works if I have something like Adapter Nano Socket, but if the word or description in this field starts with Na, it won't send the email. How do you set this up so that it allows Nano Socket to go through too, but if it's just NA, then it won't? Do I need to only test for N/A and make the user type N/A instead of NA? What does this do: ^? Thanks.

             

            Andy

            • 3. Re: NEQ text string
              nic_tunney Adobe Community Professional

              I think I misunderstood your original request, and not sure I am clear yet.  ^ in regex anchors to the beginning of the string.  If you want to see if the string starts with NA or N/A and can be followed by any number of characters, this should work:

              <cfif isDefined(myField) and NOT REFindNoCase("^(N\/A|NA).*", myField)>

               

              .* allows for any number of characters after it matches either NA or N/A at the beginning of the string.  If that isn't what you are trying to do, please clarify and I'm happy to provide a response.

              • 4. Re: NEQ text string
                Steve Sommers Level 4

                How about:

                 

                <cfif isDefined("form.Open_Jobs_Affected#id#") and NOT reFindNoCase(form["Open_Jobs_Affected#id#"],"^(N\/A|NA)($|\s)")>...

                • 5. Re: NEQ text string
                  jamie61880 Level 1

                  Steve and Nic,

                        This is what I used each time to see if the email would go through or not:

                  N/A

                  NA

                  Nano Socket

                  Socket Nano

                   

                     Steve, yours almost works perfect too, but it did not catch the N/A. The NA did not send an email. That is good. It allowed Nano Socket and Socket Nano to go through, which is good, but the N/A should not have sent an email and it did.

                      Nic, your code did not send the Nano Socket one. It should have. I think it didn't because Na is in the word "Nano". It sent the Socket Nano one which is good.

                      Is this even possible to do both N/A and NA? Or should I just look for the N/A since there are other words like Nano that could be entered as a first word? Then I could just tell everyone that need to enter N/A and they cannot use NA.

                   

                  Andy

                  • 6. Re: NEQ text string
                    nic_tunney Adobe Community Professional

                    Just add a space:

                    <cfif isDefined(myField) and NOT REFindNoCase("^(N\/A|NA)\s.*", myField)>

                    • 7. Re: NEQ text string
                      Steve Sommers Level 4

                      Then add the period (the space is already accounted for):

                       

                      <cfif isDefined("form.Open_Jobs_Affected#id#") and NOT reFindNoCase(form["Open_Jobs_Affected#id#"],"^(N\/A|NA)($|\s|\.)")>...

                      • 8. Re: NEQ text string
                        jamie61880 Level 1

                        Nic,

                            Your code emailed all 4 possible ways. That is not correct because it should have caught the N/A and NA.

                         

                        Steve,

                            Your code still sent the N/A option. It shouldn't have. The others are correct because it sent the Nano Socket and Socket Nano and didn't send the NA one which is good, but why is it sending the N/A option?

                         

                        Andy

                        • 9. Re: NEQ text string
                          nic_tunney Adobe Community Professional

                          How about just doing it using non-regex then:

                          <cfif NOT listContainsNoCase("NA,N/A", trim( left(myField, 3)))>

                          • 10. Re: NEQ text string
                            Steve Sommers Level 4

                            Apparently an extra backslash threw it off. Here is my quick test of the regular expression search:

                             

                            <cfoutput>

                              <cfloop index="variables.teststr" list="NA,NA.,N/A,N/A.,Nana says hi!,This nano rocks.">

                               #variables.teststr# = <cfif reFindNoCase(variables.teststr,"^(N/A|NA)($|\s|\.)")>FOUND<cfelse>not found</cfif><br />

                              </cfloop>

                            </cfoutput>

                             

                            My test results are as follows:

                             

                            NA = FOUND

                            NA. = FOUND

                            N/A = FOUND

                            N/A. = FOUND

                            Nana says hi! = not found

                            This nano rocks. = not found

                             

                            Assuming this is correct, your statement should read:

                             

                            <cfif isDefined("form.Open_Jobs_Affected#id#") and NOT reFindNoCase(form["Open_Jobs_Affected#id#"],"^(N/A|NA)($|\s|\.)")>...

                            • 11. Re: NEQ text string
                              jamie61880 Level 1

                              Nic, I've marked yours as the correct answer because I guess we are only going to ever enter N/A or NA at the beginning of the text box, so that is the one that works the best for us. Thank you Nic and Steve for all your help. I really appreciate it.

                              Andy