Jump to content

Input with only one Dot.


Recommended Posts

Hi guys,

I have this code that let the user put his first dot last name is there anyway I can limit the entry for one DOT only ?

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#pragma compile(AutoItExecuteAllowed, true)
#Include <GUIConstants.au3>
#Include <EditConstants.au3>
#Include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
AutoItSetOption('MouseCoordMode', 0)
AutoItSetOption('SendKeyDelay', 5)

$Form1 = GUICreate("Name", 238, 101, -1, -1)
$Input = GUICtrlCreateInput("", 16, 32, 209, 21)
GUICtrlSetLimit(-1, 22)
$Label1 = GUICtrlCreateLabel("Please type First.Last Name in here:", 16, 8, 209, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Submit = GUICtrlCreateButton("Submit", 64, 64, 105, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

Global $Name

GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

; disallow some special chars
local $DisallowedCharsTable = '(?i)[\!\@\#\$\%\^\&\*\(\)1(\)2(\)3(\)4(\)5(\)6(\)7(\)8(\)9(\)0\/\\\+\-\_\=\~(\)`\}\{\]\[(\)"(\)''(\)\;\?\>\<\,\:\|]' ;   precede special chars with a '\' just for safety (some are required, some not)

 While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
                        Case $Submit
                        $Name = GUICtrlRead($Input)

                        If $Name = '' Then
                        MsgBox(16, "Error", "You did not type any name please restart the program again. " & $Name)
                        Exit
                        EndIf
GUIDelete($Form1)
ExitLoop

        EndSwitch

 WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    ; Loop

        ; Read input text
    Local $sCurrText = GUICtrlRead($Input)
    ; If there is a space
    If StringRegExp($sCurrText, '\x20') Then
        ; Then delete it
        GUICtrlSetData($Input, StringRegExpReplace($sCurrText, '\x20', ""))
        $sLastText = GUICtrlRead($Input)
    EndIf

    Switch BitAND($wParam, 0xFFFF)
        Case $Input
                Switch BitShift($wParam, 16)
                    Case $EN_UPDATE
                        guictrlsetdata($Input,stringregexpreplace(guictrlread($Input),$DisallowedCharsTable,''))

                EndSwitch

    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc


 MsgBox(0,'Result', 'This is the result : ' & $Name)

 

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

    No registered users viewing this page.

×
×
  • Create New...