n3wbie Posted March 16, 2017 Posted March 16, 2017 (edited) Can we custom format input box ? Like if i have a telphone number as 123456789 Can it be validated as 123-456-7890 Actually i want to do it as alpha numeric Like first 5 characters as alphabets than a space than next 4 as numbers than again space and last again a single letter? Eg Input abcde1234f to become abced 1233 f I know i can do it in backend reading whole string and formating it But i want to block input something similar to $esnumber Edited March 16, 2017 by n3wbie Added some extra information for better understamding
InunoTaishou Posted March 16, 2017 Posted March 16, 2017 I don't think there's anything like $ESNUMBER For this, you could use a regexp to figure out if the input matches what you want then set the input to the correct format #include <GUIConstants.au3> #include <WinApi.au3> #include <Array.au3> Global $hMain = GUICreate("Example", 200, 40) Global $inpInput = GUICtrlCreateInput("", 10, 10, 180, 20) GUIRegisterMsg($WM_COMMAND, WM_COMMAND) GUISetState(@SW_SHOW, $hMain) While (True) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit 0 EndSwitch WEnd Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $aRegExp Switch (_WinAPI_HiWord($wParam)) Case $EN_CHANGE Switch (_WinAPI_LoWord($wParam)) Case $inpInput $aRegExp = StringRegExp(GUICtrlRead($inpInput), "([a-zA-Z]{5})([0-9]{4})([a-zA-Z]{1})", 3) If (Not @error) Then GUICtrlSetData($inpInput, _ArrayToString($aRegExp, "-")) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND n3wbie 1
spudw2k Posted March 29, 2017 Posted March 29, 2017 Another similar solution to what @InunoTaishou provided...just to give another example to play with. Reveal hidden contents Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Malkey Posted April 5, 2017 Posted April 5, 2017 (edited) This example auto-formats the input data to a particular sequence of characters. For example 5 lowercase letters, followed by 4 digits, followed by 1 lowercase letter, like "abcde1234f ", becomes "abcde 1234 f ". expandcollapse popup#include <GUIConstants.au3> #include <WinApi.au3> #include <Array.au3> ; https://www.autoitscript.com/forum/topic/187551-custom-formating-text-in-inputbox-possible/ Global $hMain = GUICreate("Example", 300, 150) GUISetFont(10) Global $inpInput = GUICtrlCreateInput("", 10, 10, 180, 20) GUICtrlCreateLabel('Format: "aaaaa dddd a" (without added spaces)' & @CRLF & _ "Where:-" & @CRLF & @TAB & _ '"a" is a lowercase letter, (a-z), and;' & @CRLF & @TAB & _ '"d" is a digit (0-9).', 10, 35, 280, 70) GUICtrlSetFont(-1, 9) GUIRegisterMsg($WM_COMMAND, _WM_COMMAND) GUISetState(@SW_SHOW, $hMain) While (True) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; abced 1233 f If BitAND($wParam, 0x0000FFFF) = $inpInput Then Local $s = StringRegExpReplace(GUICtrlRead($inpInput), "[^\p{Ll}0-9]", "") ; Remove all characters that ae not lowercase letters nor digits. Switch StringLen($s) Case 0 To 5 $s = StringRegExpReplace($s, "[^\p{Ll}]", "") GUICtrlSetData($inpInput, $s) Case 6 To 9 $s = StringLeft($s, 5) & StringRegExpReplace(StringTrimLeft($s, 5), "[^0-9]", "") ;Remove all characters that ae not digits. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6)) Case 10 To 12 $s = StringLeft($s, 9) & StringRegExpReplace(StringTrimLeft($s, 9), "[^\p{Ll}]", "") ; Remove all characters that ae not lowercase letters. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6, 4) & " " & StringMid($s, 10, 1)) EndSwitch EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_COMMAND And here is an updated version. expandcollapse popup#include <GUIConstants.au3> #include <WinApi.au3> #include <Array.au3> ; https://www.autoitscript.com/forum/topic/187551-custom-formating-text-in-inputbox-possible/?do=findComment&comment=1349344 GUIRegisterMsg($WM_COMMAND, _WM_COMMAND) Global $a = _FormatedInput() ; Get formated data from input. MsgBox(0, "Results", $a) Func _FormatedInput() local $Res Global $hFormatedInput = GUICreate("Example", 300, 150) Global $inpInput = GUICtrlCreateInput("", 10, 10, 180, 25) GUICtrlSetFont(-1, 11) Local $idBut = GUICtrlCreateButton("Done", 200, 10, 80, 25) GUICtrlCreateLabel('Format: "aaaaa dddd a" (without added spaces)' & @CRLF & _ "Where:-" & @CRLF & @TAB & _ '"a" is a lowercase letter, (a-z), and;' & @CRLF & @TAB & _ '"d" is a digit (0-9).', 10, 40, 280, 70) GUICtrlSetFont(-1, 9) GUISetState(@SW_SHOW, $hFormatedInput) While 1 Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE, $idBut $iLen = StringLen(StringRegExpReplace(GUICtrlRead($inpInput), "[^\p{Ll}0-9]", "")) ; Remove all characters that ae not lowercase letters nor digits. ConsoleWrite($iLen & @CRLF) If $iLen < 10 Then $iReply = MsgBox(33, "Error", "Only " & $iLen & " characters entered !!" & @CRLF & _ ; 1 OK (1) and Cancel (2) + 32 Question-mark icon 'Press "OK" to accept input data as is, or;' & @CRLF & _ 'Press "Cancel" to continue to enter input data.') If $iReply = 1 Then ; OK (1) Pressed ExitLoop ; Accept lesser length input. Else ControlFocus($hFormatedInput, "", $inpInput) ; Return focus to input EndIf Else ExitLoop EndIf EndSwitch WEnd $Res = GUICtrlRead($inpInput) GUIDelete($hFormatedInput) Return $Res EndFunc ;==>_FormatedInput ; Ref to: https://www.autoitscript.com/forum/topic/180138-custom-input-mask/?do=findComment&comment=1293201 Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; abcde 1234 f If $hWnd = $hFormatedInput And _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $inpInput Then Local $s = StringRegExpReplace(GUICtrlRead($inpInput), "[^\p{Ll}0-9]", "") ; Remove all characters that ae not lowercase letters nor digits. Switch StringLen($s) Case 1 To 5 $s = StringRegExpReplace($s, "[^\p{Ll}]", "") GUICtrlSetData($inpInput, $s) ;ConsoleWrite(StringLen($s) & " 0-6 " & $s & @CRLF) Case 6 To 9 $s = StringLeft($s, 5) & StringRegExpReplace(StringTrimLeft($s, 5), "[^0-9]", "") ;Remove all characters that ae not digits. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6)) ;ConsoleWrite(StringLen($s) & " 6-9 " & $s & @CRLF) Case 10 To 11 $s = StringLeft($s, 9) & StringRegExpReplace(StringTrimLeft($s, 9), "[^\p{Ll}]", "") ; Remove all characters that ae not lowercase letters. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6, 4) & " " & StringMid($s, 10, 1)) ;ConsoleWrite(StringLen($s) & " 10-11 " & $s & @CRLF) EndSwitch EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_COMMAND Edited April 12, 2017 by Malkey n3wbie 1
n3wbie Posted April 14, 2017 Author Posted April 14, 2017 On 4/5/2017 at 11:12 PM, Malkey said: This example auto-formats the input data to a particular sequence of characters. For example 5 lowercase letters, followed by 4 digits, followed by 1 lowercase letter, like "abcde1234f ", becomes "abcde 1234 f ". expandcollapse popup#include <GUIConstants.au3> #include <WinApi.au3> #include <Array.au3> ; https://www.autoitscript.com/forum/topic/187551-custom-formating-text-in-inputbox-possible/ Global $hMain = GUICreate("Example", 300, 150) GUISetFont(10) Global $inpInput = GUICtrlCreateInput("", 10, 10, 180, 20) GUICtrlCreateLabel('Format: "aaaaa dddd a" (without added spaces)' & @CRLF & _ "Where:-" & @CRLF & @TAB & _ '"a" is a lowercase letter, (a-z), and;' & @CRLF & @TAB & _ '"d" is a digit (0-9).', 10, 35, 280, 70) GUICtrlSetFont(-1, 9) GUIRegisterMsg($WM_COMMAND, _WM_COMMAND) GUISetState(@SW_SHOW, $hMain) While (True) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; abced 1233 f If BitAND($wParam, 0x0000FFFF) = $inpInput Then Local $s = StringRegExpReplace(GUICtrlRead($inpInput), "[^\p{Ll}0-9]", "") ; Remove all characters that ae not lowercase letters nor digits. Switch StringLen($s) Case 0 To 5 $s = StringRegExpReplace($s, "[^\p{Ll}]", "") GUICtrlSetData($inpInput, $s) Case 6 To 9 $s = StringLeft($s, 5) & StringRegExpReplace(StringTrimLeft($s, 5), "[^0-9]", "") ;Remove all characters that ae not digits. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6)) Case 10 To 12 $s = StringLeft($s, 9) & StringRegExpReplace(StringTrimLeft($s, 9), "[^\p{Ll}]", "") ; Remove all characters that ae not lowercase letters. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6, 4) & " " & StringMid($s, 10, 1)) EndSwitch EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_COMMAND And here is an updated version. expandcollapse popup#include <GUIConstants.au3> #include <WinApi.au3> #include <Array.au3> ; https://www.autoitscript.com/forum/topic/187551-custom-formating-text-in-inputbox-possible/?do=findComment&comment=1349344 GUIRegisterMsg($WM_COMMAND, _WM_COMMAND) Global $a = _FormatedInput() ; Get formated data from input. MsgBox(0, "Results", $a) Func _FormatedInput() local $Res Global $hFormatedInput = GUICreate("Example", 300, 150) Global $inpInput = GUICtrlCreateInput("", 10, 10, 180, 25) GUICtrlSetFont(-1, 11) Local $idBut = GUICtrlCreateButton("Done", 200, 10, 80, 25) GUICtrlCreateLabel('Format: "aaaaa dddd a" (without added spaces)' & @CRLF & _ "Where:-" & @CRLF & @TAB & _ '"a" is a lowercase letter, (a-z), and;' & @CRLF & @TAB & _ '"d" is a digit (0-9).', 10, 40, 280, 70) GUICtrlSetFont(-1, 9) GUISetState(@SW_SHOW, $hFormatedInput) While 1 Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE, $idBut $iLen = StringLen(StringRegExpReplace(GUICtrlRead($inpInput), "[^\p{Ll}0-9]", "")) ; Remove all characters that ae not lowercase letters nor digits. ConsoleWrite($iLen & @CRLF) If $iLen < 10 Then $iReply = MsgBox(33, "Error", "Only " & $iLen & " characters entered !!" & @CRLF & _ ; 1 OK (1) and Cancel (2) + 32 Question-mark icon 'Press "OK" to accept input data as is, or;' & @CRLF & _ 'Press "Cancel" to continue to enter input data.') If $iReply = 1 Then ; OK (1) Pressed ExitLoop ; Accept lesser length input. Else ControlFocus($hFormatedInput, "", $inpInput) ; Return focus to input EndIf Else ExitLoop EndIf EndSwitch WEnd $Res = GUICtrlRead($inpInput) GUIDelete($hFormatedInput) Return $Res EndFunc ;==>_FormatedInput ; Ref to: https://www.autoitscript.com/forum/topic/180138-custom-input-mask/?do=findComment&comment=1293201 Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; abcde 1234 f If $hWnd = $hFormatedInput And _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $inpInput Then Local $s = StringRegExpReplace(GUICtrlRead($inpInput), "[^\p{Ll}0-9]", "") ; Remove all characters that ae not lowercase letters nor digits. Switch StringLen($s) Case 1 To 5 $s = StringRegExpReplace($s, "[^\p{Ll}]", "") GUICtrlSetData($inpInput, $s) ;ConsoleWrite(StringLen($s) & " 0-6 " & $s & @CRLF) Case 6 To 9 $s = StringLeft($s, 5) & StringRegExpReplace(StringTrimLeft($s, 5), "[^0-9]", "") ;Remove all characters that ae not digits. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6)) ;ConsoleWrite(StringLen($s) & " 6-9 " & $s & @CRLF) Case 10 To 11 $s = StringLeft($s, 9) & StringRegExpReplace(StringTrimLeft($s, 9), "[^\p{Ll}]", "") ; Remove all characters that ae not lowercase letters. GUICtrlSetData($inpInput, StringLeft($s, 5) & " " & StringMid($s, 6, 4) & " " & StringMid($s, 10, 1)) ;ConsoleWrite(StringLen($s) & " 10-11 " & $s & @CRLF) EndSwitch EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_COMMAND Expand thanks bro will give it a try
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