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

NEQ text string

Engaged ,
Jul 23, 2015 Jul 23, 2015

Copy link to clipboard

Copied

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

Views

441

Translate

Translate

Report

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

correct answers 1 Correct answer

Engaged , Jul 24, 2015 Jul 24, 2015

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

...

Votes

Translate

Translate
Engaged ,
Jul 24, 2015 Jul 24, 2015

Copy link to clipboard

Copied

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

...

Votes

Translate

Translate

Report

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
Engaged ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Engaged ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Advocate ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

How about:

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

Votes

Translate

Translate

Report

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
Engaged ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Engaged ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

Just add a space:

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

Votes

Translate

Translate

Report

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
Advocate ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Engaged ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Engaged ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

How about just doing it using non-regex then:

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

Votes

Translate

Translate

Report

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
Advocate ,
Jul 31, 2015 Jul 31, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Engaged ,
Aug 03, 2015 Aug 03, 2015

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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
Resources
Documentation