Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

Handling special characters

An operator is to enter only alphanumeric data through a standard PC keyboard. Can Lookout be configured to filter out or flag as errors any punctuation or special characters (#, &, {, etc.) entered?
0 Kudos
Message 1 of 8
(4,004 Views)
HDP,

To flag an invalid string, you would have to create an expression for each character as follows:
find(".",text1,1)=0

If this evaluates to true, then there are no periods in the expression. You can do this for each unwanted character and have one expression that check to see if any of these are false. This would requires several expressions, but it should do the job.

Regards,
Michael Shasteen
Applications Engineering
National Instruments
www.ni.com/ask
Message 2 of 8
(4,004 Views)
So, would an expression like this work?

invld_chr = (find("!",text_string,1)=0) or (find("@",text_string,1)=0) or {append as many find expressions as needed.
Message 3 of 8
(4,004 Views)
Make sure that you use a "!" (not) so that the expression will be true if any invalid characters are found:

invld_chr = !(find("!",text_string,1)=0) or !(find("@",text_string,1)=0) or !...
0 Kudos
Message 4 of 8
(4,004 Views)
I cannot make this work:

invld_chr = !(find("!",text_string,1)=0) or !(find("@",text_string,1)=0) or !..."

This is what I found does work for me:

invld_chr = (find("?",text_string,1)>0) or ...

The not symbol (!) causes the expression editor to return a syntax error when used as in the first example.
0 Kudos
Message 5 of 8
(4,004 Views)
My mistake. You must use "not" rather than "!" in front of parenthesis.

invld_chr = NOT(find("!",text_string,1)=0) or NOT(find("@",text_string,1)=0) or NOT..."
0 Kudos
Message 6 of 8
(4,004 Views)
Yes, that works. One more question - To filter all the special characters and punctuation on a standard PC keyboard and examining the text string variable name shown, the expression will consume well over 1100 characters. What is the practical limit on the length of an expression?

Thanks for your help.
0 Kudos
Message 7 of 8
(4,004 Views)
We have not designed a limit into Lookout, nor have we found one during testing.
0 Kudos
Message 8 of 8
(4,004 Views)