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
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)>
...
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)>
...
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
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.
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)")>...
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
Copy link to clipboard
Copied
Just add a space:
<cfif isDefined(myField) and NOT REFindNoCase("^(N\/A|NA)\s.*", myField)>
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|\.)")>...
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
Copy link to clipboard
Copied
How about just doing it using non-regex then:
<cfif NOT listContainsNoCase("NA,N/A", trim( left(myField, 3)))>
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|\.)")>...
Copy link to clipboard
Copied
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