Jump to content

Recommended Posts

Posted

Hi.

I was wondering if its possible in some way to make a Masked Text Box in autoit.

I want to use it for users to enter a phone number and to make sure they write it in the correct format (__ __ __ __) and dont use illegal characters and such.

Is this possible ?

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Posted

Could you give me a headstart on how to do this ? :)

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Posted

This can be a start, I don't know how is phone numbers in your contry, this code make there input to accept just digits and char "-". You need just to set positions where can be this char "-" or other rules.

Global $MAIN, $INPUT, $LAST = ""

$MAIN = GUICreate("Example",200,200)
$INPUT = GUICtrlCreateInput("",50,90,100,20)
GUISetState(@SW_SHOW,$MAIN)
AdlibRegister("CheckInput")

While True
    Switch GUIGetMsg()
        Case -3
            AdlibUnRegister("CheckInput")
            Exit
    EndSwitch
    Sleep(10)
WEnd

Func CheckInput()
    $TEXT = GUICtrlRead($INPUT)
    If $TEXT <> $LAST Then
        $LAST = StringRegExpReplace($TEXT,"[^-[:digit:]]","")
        GUICtrlSetData($INPUT,$LAST)
    EndIf
EndFunc
Posted

Thanks alot :)

I was looking for something that looks abit like the attached image

asd.bmp

I just realized it didnt attach my picture on the first post, so i'll try again :)

I hope its possible :P

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Posted

Kiesp, why don't you use an input with $ES_NUMBER style? This way the user is restricted to use only numbers.

taietel

Ya, i guess i could just do that ^^

What i actually wanted was the underscores marking how much and where to write and also the spaces :)

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Posted

Maybe something like this, for a mask [## ## ## ##]:

Global $MAIN, $INPUT, $LAST

$MAIN = GUICreate("Example",200,200)
$INPUT = GUICtrlCreateInput("",50,90,100,20)
GUISetState(@SW_SHOW,$MAIN)
AdlibRegister("CheckInput")

While True
    Switch GUIGetMsg()
        Case -3
            AdlibUnRegister("CheckInput")
            Exit
    EndSwitch
    Sleep(10)
WEnd

Func CheckInput()
    $TEXT = GUICtrlRead($INPUT)
    If $TEXT <> $LAST Then
        $MASK = StringRegExpReplace($TEXT,"(?x)[^[:digit:]]","")
        $LAST = StringStripWS(StringMid($MASK,1,2) & " " & StringMid($MASK,3,2) & " " & StringMid($MASK,5,2) & " " & StringMid($MASK,7,2),2)
        GUICtrlSetData($INPUT,$LAST)
    EndIf
EndFunc
Posted

Once again, thanks Andreik :)

I changed the code a bit so now it almost fits my needs :)

Global $MAIN, $INPUT, $LAST
#Include <GuiEdit.au3>
#include <EditConstants.au3>

$MAIN = GUICreate("Example",200,200)
$INPUT = GUICtrlCreateInput("",50,90,100,20,$ES_NUMBER)
GUISetState(@SW_SHOW,$MAIN)
_GUICtrlEdit_SetLimitText($INPUT,11)
AdlibRegister("CheckInput")

While True
    Switch GUIGetMsg()
        Case -3
            AdlibUnRegister("CheckInput")
            Exit
    EndSwitch
    Sleep(10)
WEnd

Func CheckInput()
    $TEXT = GUICtrlRead($INPUT)
    ;If $TEXT <> $LAST Then
        $MASK = StringRegExpReplace($TEXT,"(?x)[^[:digit:]]","")
        $LAST = StringStripWS(StringMid($MASK,1,2) & " " & StringMid($MASK,3,2) & " " & StringMid($MASK,5,2) & " " & StringMid($MASK,7,2),2)
        GUICtrlSetData($INPUT,$LAST)
    ;EndIf
EndFunc

but i was thinking is there a way for i can get rid of the "$MASK = StringRegExpReplace($TEXT,"(?x)[^[:digit:]]","")" line, since it just seems like double work since i use $ES_NUMBER like taietel suggested ?

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Posted

It's good $ES_NUMBER when you don't need other chars like SPACE. In this case we have some spaces between numbers.

it doesnt really matter if i have $ES_NUMBER or not.. im not allowed to make spaces either way.. i'll just leave it there :)

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Posted

But I saw you put as comment there conditional statement from CheckInput() function. I think is better with because will not keep set the same text if is not changed.

Posted (edited)

the script seems to be working just as i want it to with my changes, so i thank you alot for your help :)

edit: ah.. just realised that i cant use the arrow buttons to change position in the text unless i got your if in the loop ^^ i'll bring it back :)

Edited by Kiesp

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

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
  • Recently Browsing   0 members

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