Sign in to follow this  
Followers 0
BryonR

Force / Require String input

4 posts in this topic

I want to force a user to input a string of <Character>######### example A123456789

I understand how to force the field to have input just not the type or sting that I want.

Thanks!

Bryon

Share this post


Link to post
Share on other sites



What I usually do when I need something like this is have it check the string each time it is changed, and if it is wrong, revert it back to what it was before. For instance:

If $newString <> $oldString Then
   ; Do your checks to make sure it is formatted right.
    If $formattedWrong Then
        GUICtrlSetData($input, $oldString); or ControlSetText
    EndIf
Endif

Regards,Josh

Share this post


Link to post
Share on other sites

What I usually do when I need something like this is have it check the string each time it is changed, and if it is wrong, revert it back to what it was before. For instance:

If $newString <> $oldString Then
  ; Do your checks to make sure it is formatted right.
    If $formattedWrong Then
        GUICtrlSetData($input, $oldString); or ControlSetText
    EndIf
Endif
how do I check to see if the format was correct? Thats the part I'm stuck at.

Share this post


Link to post
Share on other sites

You might want to use regular expressions:

$input= "A123"
if StringRegExp($input, "^A[0-9]+$") then
  ; ...
else
  ; ...
endif

^A[0-9]+$ matches "A0" to "A999999999999999999999999999" (and even more digits). You might want to require a specific length:

^A[0-9]{1,10}$

Here, 1 is minimum and 10 is maximum number of digits.

Regards, bmaker

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0