Jump to content
Sign in to follow this  

Letters in "Input"

Recommended Posts

Hi all,

How do I allow an input control (GUICtrlCreateInput) to get only digits and dots?

$ES_NUMBER - allows only digits, but I need to be able to type something like this only:   2.15.1598.1

Can you help me please? 

Share this post

Link to post
Share on other sites

use the on change event to assess the text field of the inputbox

if it's always the same number of dots and sets of digits you could have four input boxes, one for each number and append them together at the end separated by dots.  Use the $ES_NUMBER control style to restrict input to numbers only.

Edited by gruntydatsun
corrected error

Share this post

Link to post
Share on other sites

Try this.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>


$hGui = GUICreate("My GUI edit")

$IP = GUICtrlCreateInput("", 10, 15, 200, 22)
$IP2 = GUICtrlCreateInput("", 10, 40, 80, 22)

GUICtrlCreateLabel("<- Digits and dots only.", 215, 15, 200, 22)
GUICtrlSetFont(-1, 12)
GUICtrlCreateLabel('<-  "n.nn.nnnn.n" pattern only.', 95, 40, 300, 22)
GUICtrlSetFont(-1, 12)


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then ; Only digits and dots
        If $nNotifyCode = $EN_CHANGE Then
            GUICtrlSetData($IP, StringRegExpReplace(GUICtrlRead($IP), "[^0-9.]+", ""))
    If $nID = $IP2 Then ; Allow n.nn.nnnn.n characters only - where n is a digit. For example 2.15.1598.1 is allowed.
        If $nNotifyCode = $EN_CHANGE Then
            $temp2 = GUICtrlRead($IP2)
            $REPattern = "\d\.\d\d\.\d\d\d\d\.\d"
            $iLen = StringLen($temp2)
            If StringRegExp($temp2, StringLeft($REPattern, $iLen * 2)) = 0 Or $iLen > 11 Then GUICtrlSetData($IP2, StringTrimRight($temp2, 1))
EndFunc   ;==>WM_COMMAND


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      Hi dears
      How are you?
      I have a question, to you please.
      How do I create an edit box for numbers only and does not accept letters? using autoit
      greetings to all
      I hope you help ME
      Thanks to all in advance
    • By coffeeturtle
      Hello. I need to perform a specific string replace, but not sure how to go about it.
      The scenario is this: I have a large block of text. Within the text colons appear ":",  Sometimes the colons are used in a sentence appearing after a word. Other times they appear in between numbers like a ratio or a sport score (e.g. "6:8").
      I want to replace the colons appearing between numeric values like 6:8 with the word "to", but not the ones appearing at the end of a sentence.
      Is there a way that I can have StringReplace (or any other method) differentiate when to replace the colon based on it appearing between numbers?
      I did try searching for a similar scenario.
      Thank you for any help. 
    • By ur
      I was wondering if there is an efficient premade algorithm for determining if the sum/difference of a group of numbers can equal a different number. Example:
      5, 8, 10, 2, using + or -, to equal 9. 5 - 8 = -3 + 10 = 7 + 2 = 9
      It is somewhere nearer to Knapsack problem.
      Thanks in Advance.
    • By PCI
      Hi everyone 
      I've read all yesterday forums , i think it's me , but i could not find a clue for this :
      I need to generate large numbers and output into csv format or excel format
      - Range between 3000000 and 9000000 
      - Need 5000000 numbers
      - Numbers should not be in series ( Mixed and Random )
      - I would prefere to have a check digits at the end
      Anyone could help please ?
      Thank you
    • By TheAutomator
      hi everyone!
      I need some help with my rpn calculator.
      I first translated it from vbscript to autoitscript and that's when i stumbled on problem one:
      (46) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
      $Stack[ubound($Stack)] = $Item
      ^ ERROR
      After that (and i know this from testing it as a vbscript) it can't work with negative numbers:
      "1 - - 2" to Reverse Polish notation = "1 - 2 -" gives me the build in error...
      Can you guy's help me with my code pleas?
      Func Print($what,$er = 0) $t = '' if $err <> 0 then $t = 'ERROR!' MsgBox($er,$st,$what) EndFunc Func RPN($Tokenarray) Local $Stack = [] Local $Result Local $Operator_B Local $Operator_A For $Token = 0 To Ubound($Tokenarray) If Isoperator($Tokenarray[$Token]) Then $Operator_B = Pop($Stack) $Operator_A = Pop($Stack) If $Operator_A = "" Then Print("The user has not input sufficient values in the expression.",16) exit EndIf Switch $Tokenarray[$Token] Case "+" $Result = Number($Operator_A,3) + Number($Operator_B,3) Case "-" $Result = Number($Operator_A,3) - Number($Operator_B,3) Case "*" $Result = Number($Operator_A,3) * Number($Operator_B,3) Case "/" $Result = Number($Operator_A,3) / Number($Operator_B,3) Case "^" $Result = Number($Operator_A,3) ^ Number($Operator_B,3) EndSwitch Push($Result,$Stack) Else Push($Tokenarray[$Token],$Stack) EndIf Next If Ubound($Stack) > 1 Then Print("The user input has too many values.",16) Exit EndIf Return pop($Stack) EndFunc Func Push($Item, Byref $Stack) If Ubound($Stack) > -1 Then Redim $Stack[Ubound($Stack) + 1] $Stack[Ubound($Stack)] = $Item Else Local $Stack = [$Item] EndIf EndFunc Func Pop($Stack) $pop = "" If Ubound($Stack) > -1 Then $Pop = $Stack[Ubound($Stack)] Redim $Stack[Ubound($Stack) - 1] EndIf Return $pop EndFunc Func Peek($Stack) $peek = "" If Ubound($Stack) > -1 Then $Peek = $Stack(Ubound($Stack)) EndIf Return $peek EndFunc Func Isoperator($Operator) Return StringInstr("+-*/^&<=>", $Operator) <> 0 And StringLen($Operator) = 1 EndFunc Func Precedence($Operator) If Isoperator($Operator) Then Switch $Operator case "^" Return 4 case "*","/" Return 3 case "+","-" Return 2 case "&" Return 1 case "<","=",">" Return 0 EndSwitch EndIf EndFunc ;################################################################################################## ; (4 - -5) = (4|-|-|5) = (4|-|5|-) ; input tokens rpn Global $calculate_this = ["4","-","5","-"] Print(rpn($calculate_this)) thanks in advance ,
  • Create New...