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)>
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.
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.
<cfif isDefined("form.Open_Jobs_Affected#id#") and NOT reFindNoCase(form["Open_Jobs_Affected#id#"],"^(N\/A|NA)($|\s)")>...
Steve and Nic,
This is what I used each time to see if the email would go through or not:
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.
Just add a space:
<cfif isDefined(myField) and NOT REFindNoCase("^(N\/A|NA)\s.*", myField)>
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|\.)")>...
Your code emailed all 4 possible ways. That is not correct because it should have caught the N/A and NA.
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?
How about just doing it using non-regex then:
<cfif NOT listContainsNoCase("NA,N/A", trim( left(myField, 3)))>
Apparently an extra backslash threw it off. Here is my quick test of the regular expression search:
<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 />
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|\.)")>...
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.