LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

restricting string length using regular expressions

Hi all,

 

Can I restrict the string length to a certain value using regular expressions.

 

I have read other threads of restricting the string lengths. But I am just thinking if there is a smart way to work it out...

 

Can anyone form the reg-ex to restrict the string and post it ??

 

I am using the following reg-ex but its not helping me.

 

string.matches(/^\d+[A-Z]\d+$/) && string.length >= 0 && string.length <= 100

 

Thanks.

0 Kudos
Message 1 of 6
(5,359 Views)

You can set the control to 'Update while typing' then use and event case for 'value change' check the string length and disable the control if it is at the max length.

 

 

0 Kudos
Message 2 of 6
(5,342 Views)

It is not clear what kind of "string" you are talking about. Is the string a user input control or the result of some string operations?

 

If this is a control, I would recommend making it an Xcontrol and do validations inside it.

If this is just a wire, all you probably need is "String subset" with the desired lenght.

 

Can you provide a bit more details.

Message 3 of 6
(5,339 Views)

As the others have asked

 

"What kind of string are you talking about?"  

 

If all you want is the cut a string lenght  to 100 then use the String Subset function

 

But if you must use a Regular Expression then use the curlly brackets { } as in

 

^.{0,100}

^\w{0,100}

^\S{0,100}

 

 

  • \w - Matches any word character; equivalent to [a-zA-Z0-9_]
  • \S - Matches any non-white space character
  •  

    Omar

    0 Kudos
    Message 4 of 6
    (5,329 Views)

    Thank you Omar. I guess I will check out how the reg-ex works for me and will let you know. Well, getting a simple sub-sting output should also help me.

     

    Its a string control that I have and want to restrict the user from entering more than 100 characters . Can I get more info about the XControls.

     

    Thanks.

    0 Kudos
    Message 5 of 6
    (5,311 Views)

    XControls are special type of controls wherein they also have the code associated with them, unlike the Controls/Typedefs which dont have any code associated with them.

     

    XControls have different Abilites like Data, State, Facade & Init/Uninit.

     

    Read this for more details. Smiley Happy

    - Partha ( CLD until Oct 2024 🙂 )
    0 Kudos
    Message 6 of 6
    (5,305 Views)