LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Any way to limit the input format for string control?

Hi there,

  I need a control for the user to input some string with only alphabets and no special characters. Also need to control the number of characters to input. I search it and see someone use Xcontrol to achieve that but I really have no idea how to get that. Any other way to get this function works on string input?

0 Kudos
Message 1 of 12
(5,643 Views)

Set the string to "single line" and "update while typing". Use a filtering key-down event and discardunwanted characters of characters past the max length.

 

(Make sure not to filter edit keys, such as backspace, etc.)

 

(look at my very old example for ideas.)

0 Kudos
Message 2 of 12
(5,627 Views)

@altenbach wrote:

Set the string to "single line" and "update while typing". Use a filtering key-down event and discardunwanted characters of characters past the max length.

 

(Make sure not to filter edit keys, such as backspace, etc.)

 

(look at my very old example for ideas.)


Thanks a lot. But that's works on in run time not in edit mode, right?

0 Kudos
Message 3 of 12
(5,606 Views)

You did not specify edit mode functionality. If you need that, you need to build an x-control.

0 Kudos
Message 4 of 12
(5,597 Views)

@altenbach wrote:

You did not specify edit mode functionality. If you need that, you need to build an x-control.


my bad. It seems that x-control is the only way to achieve that. I don't know how to program x-control, I found two examples online but it seems that we need to create the appearance ourselve. Is it possible to inherit the control for built-in string or slive string and modify the behavior to get that. I want to keep all controls the same appearance.

0 Kudos
Message 5 of 12
(5,589 Views)

You have full control over the appearance of the x-control. I don't understand your concern.

0 Kudos
Message 6 of 12
(5,583 Views)

Dear Altenbach,

 

The VI that you have posted in (Max8Discard.vi) in Limiting Input String Length

limits the entry of string control to required length but it doesnt limit the entry of special characters.

 

If you have any simple way to do the same it will be very helpful

 

Thanks in advance...!!!

 

Regards,

Praveen PRVS

0 Kudos
Message 7 of 12
(5,167 Views)

@prvs wrote:

Dear Altenbach,

 

The VI that you have posted in (Max8Discard.vi) in Limiting Input String Length

limits the entry of string control to required length but it doesnt limit the entry of special characters.

 

If you have any simple way to do the same it will be very helpful

 

Thanks in advance...!!!

 

Regards,

Praveen PRVS


Just change the check after the Lexical Class function.  If you just want numbers and letters, then use the In Range & Coerce function to check for class numbers 3 through 5.  Play around with the logic some more until you get what you need (I'm thinking that AND should be an OR).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 12
(5,148 Views)

prvs wrote:

The VI that you have posted in (Max8Discard.vi) in Limiting Input String Length

limits the entry of string control to required length but it doesnt limit the entry of special characters.


As mentioned, the main reason is to still allow editing of the string. For example if you would filter the delete key or backspace key, you would no longer be able the edit the string while entering text. For example if the max lenght is 3, you enter "abx", and immediately notice that you actually wanted to enter "abc", you would not be able to correct the entry in the usual way.

 

You are free to change the filtering in any way you want.

0 Kudos
Message 9 of 12
(5,141 Views)

I understand the importance of not filtering the backspace or delete characters, but my requirement is to allow to the user to enter only the alpha-numeric characters and not to allow to enter special characters such as "!@#$%^&*()/*+...etc

But the shared code allows user to enter these special characters.

 

Regards,

Praveen PRVS

 

 

0 Kudos
Message 10 of 12
(5,111 Views)