Jump to content

Force / Require String input


Recommended Posts

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

Link to comment
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.
Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...