Kiesp Posted March 21, 2011 Posted March 21, 2011 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
Andreik Posted March 21, 2011 Posted March 21, 2011 By default I don't think you can do this but you can try to define one mask based on the phone number format and legal charset.
Kiesp Posted March 21, 2011 Author Posted March 21, 2011 Could you give me a headstart on how to do this ? http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D
Andreik Posted March 21, 2011 Posted March 21, 2011 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
Kiesp Posted March 21, 2011 Author Posted March 21, 2011 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 http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D
taietel Posted March 21, 2011 Posted March 21, 2011 Kiesp, why don't you use an input with $ES_NUMBER style? This way the user is restricted to use only numbers. taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Kiesp Posted March 21, 2011 Author Posted March 21, 2011 Kiesp, why don't you use an input with $ES_NUMBER style? This way the user is restricted to use only numbers.taietelYa, 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
Andreik Posted March 21, 2011 Posted March 21, 2011 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
Kiesp Posted March 21, 2011 Author Posted March 21, 2011 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
Andreik Posted March 21, 2011 Posted March 21, 2011 It's good $ES_NUMBER when you don't need other chars like SPACE. In this case we have some spaces between numbers.
Kiesp Posted March 21, 2011 Author Posted March 21, 2011 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
Andreik Posted March 21, 2011 Posted March 21, 2011 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.
Kiesp Posted March 21, 2011 Author Posted March 21, 2011 (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 March 21, 2011 by Kiesp http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now