Skip to main content
Inspiring
July 23, 2015
Answered

NEQ text string

  • July 23, 2015
  • 1 reply
  • 795 views

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

This topic has been closed for replies.
Correct answer nic_tunney

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

...

1 reply

nic_tunneyCorrect answer
Inspiring
July 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)>

...

Inspiring
July 31, 2015

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

Inspiring
July 31, 2015

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.