06-23-2009 11:12 AM
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.
06-23-2009 12:48 PM
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.
06-23-2009 12:55 PM
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.
06-23-2009 01:41 PM
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}
Omar
06-23-2009 11:52 PM
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.
06-24-2009 12:30 AM
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.