Sign in to follow this  
Followers 0
PhoenixXL

RestrictEdit_SRE (UDF)

14 posts in this topic

#1 ·  Posted (edited)

RESTRICT EDIT UDF

Restrict the text that can be entered in an editbox through a String Regular Expression.

The UDF works be subclassing the control. >Here is a similar UDF based on Windows Message.

 

Functions

  • The UDF is pretty simple and could be modified with ease.
  • User can set their SRE pattern to block the text entered in the editbox
  • Tooltips can be used in case of an error. The title of the Tooltip is Error_2 where the number(2) signifies the pattern that caused the error.
  • The script is made to use function pointer variables rather than direct patterns, to make it more flexible and broader.
  • Supports +ve and -ve SRE pattern matches. See example for better understanding.

 

Note : The Pattern should be made such that every phase of typing is met,

Example, if the user wants The second letter should be always a digit. Then he should make sure that the pattern is also satisfied when user enters the first character, as through the process of typing.

Index

; #INDEX# =======================================================================================================================
; Title .........: RestrictEdit
; Version........: 1.0
; AutoIt Version : 3.3.8.0++
; Language ......: English
; Author(s)......: Phoenix XL
; Librarie(s)....: WinAPI, Array and GUIEdit
; Description ...: Functions for restricting the text typed in an Edit control through SRE.
;                  The edit control is subclassed and the original processing is blocked when pattern isn't satisfied.
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
;_Restrict_Edit
; ===============================================================================================================================

; #INTERNAL_USE_ONLY# ===========================================================================================================
; HideToolTip_Edit
;_NewWnd_Proc_
;_SubClass_
; ===============================================================================================================================

ChangeLog

v1.0 - First Release

v2.0 - Replaced the SRE pattern parameter(2nd parameter) with function pointer parameter[A script Breaking change]. Added support for positive and negative pattern matches

Download

v2.0 RestrictEdit(UDF).7z

Previous downloads : 161

Edited by PhoenixXL
3 people like this

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites



Really Usefull . :thumbsup:

thank you. 

Share this post


Link to post
Share on other sites

NIce example of sub-classing..


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Thanks PhoenixXL

Very nice UDF

 

Unfortunately something disappoints me today my mind, 

I try to add restrictions to the text type: 
m121/12,1231/12,p1/12,2/13,s1/14,o121/10

here is an example what I want to achieve:

#include <array.au3>
$sText = 'm121/12,1231/12,p1/12,2/13,s1/14,o121/10'
$aItems = StringRegExp($sText,'[mpson]?\d+\/\d\d,?',3)
_ArrayDisplay($aItems)

I wonder how to use your UDFa to exclude erroneous data entered by a human.


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You will have to use conditionals,

Example

#include <GUIConstants.au3>
#include <RestrictEdit.au3>

#cs
    [0]|m121/12,
    [1]|1231/12,
    [2]|p1/12,
    [3]|2/13,
    [4]|s1/14,
    [5]|o121/10
#ce

Func _Main()

    #cs Pattern in text that should follow

        the first character can be any of 'm' 'p' 's' 'o' 'n' or a no. of digits
        followed by a "/" and then followed by two digits.
        Then if comma again the above pattern is expected otherwise, if EOL the pattern is satisfied.

    #ce

    Local Const $sPattern = "^([mpson]?(?(?=\d+)\d*\d(?(?=/)/(?(?=\d)\d{0,2}(,|$)|$)|$)|$))*$"

    ;our main GUI
    GUICreate("Restrict Edit | Phoenix XL", 200, 70)
    GUICtrlCreateLabel("Pattern : " & $sPattern, 10, 10, 200, 30)
    GUICtrlCreateInput("", 10, 30, 180, 20)

    ;subclass the control and set the SRE restriction.
    _Restrict_Edit(GUICtrlGetHandle(-1), $sPattern, "InCorrect Syntax.")
    If @error Then MsgBox(16, "Error Code: " &  @error, "Extended: " & @extended)

    GUISetState()

    Do
        Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;unsubclass the control
    _Restrict_Edit(GUICtrlGetHandle(-1))

EndFunc   ;==>_Main

_Main()

I'm not decoding the regex. I'm going to release the next version soon that comes with the support of multiple SRE's. Therefore such long patterns won't be required.

Regards :)

Edited by PhoenixXL
1 person likes this

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Exactly what I meant.

Thanks a lot for that script example.

 

I'm going to release the next version soon that comes with the support of multiple SRE's. Therefore such long patterns won't be required.

 

Sounds promising. Already I can not wait to study your code 

Best regards 

mLipok
 
 
btw.

Thanks for this tutorial link, is very instructiveSomehow I have not landed on him before.


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I worked a bit on it. 
The first thing I made a minor amendment. 
changing this: 
Local Const $sPattern = "^([mpson]?(?(?=\d+)\d*\d(?(?=/)/(?(?=\d)\d{0,2}(,|$)|$)|$)|$))*$"

on, something like this:

Local Const $sPattern = "^([mpson]?(?(?=\d+)\d+(?(?=/)/(?(?=\d)\d{0,2}(,|$)|$)|$)|$))*$"

d*d    >>>   d+


Then I remembered one problem: 

below a description of how to achieve the same problem: 
 
type 
1234/56
Now back to the beginning, before the digit 1, and now try to add the letter s 
 
tooltip "Incorrect Syntax." Appear. 
 
but when you clear input and start writing again 
s1234/56 
in this case no message does not appear
 
Then I did some more tests. 
 
I noticed another similar problem: 
below a description of how to achieve this problem: 
 
type 
1234/56
Now back before the character /, and now try to add the letter s   (trying to do this 1234s/56  )
 
tooltip "Incorrect Syntax." Appear. 
 
but when set at the end of the entered text, and add a comma character
and now you come back in front of the sign / 
it now can easily add the letter s

 


I wonder if this is errors in $sPattern , or have found a bug?

EDIT: nevertheless, the script is already very useful.


I have an additional question / issue, but that does not stir too much, so I wait for a possible answer.

 

Best Regards

mLipok

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Yes all the problems is due to a bug in the UDF.

I will clear it with the new version, would be released by tomorrow.

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Thank you for the information.
In the evening, I will explain this further case which I mentioned earlier.

Perhaps it will help to improve the UDF.

Regards

mLIpok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

v2.0 released

-+Replaced the SRE pattern parameter(2nd parameter) with function pointer parameter[A script Breaking change].

+Added support for positive and negative pattern matches


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

mLipok,

with the new version your example could be modified as follows (three regexes)

#include <GUIConstants.au3>
#include <RestrictEdit.au3)
#include <MsgBoxConstants.au3>

#cs
    [0]|m121/12,
    [1]|1231/12,
    [2]|p1/12,
    [3]|2/13,
    [4]|s1/14,
    [5]|o121/10
#ce

_Main()

Func _Main()

    #cs Pattern in text that should follow

        the first character can be any of 'm' 'p' 's' 'o' 'n' or a no. of digits
        followed by a "/" and then followed by two digits.
        Then if comma again the above pattern is expected otherwise, if EOL the pattern is satisfied.

    #ce

    ;our main GUI
    GUICreate("Restrict Edit | Phoenix XL", 200, 70)
    GUICtrlCreateLabel("Test", 10, 10, 200, 30)
    GUICtrlCreateInput("", 10, 30, 180, 20)

    ;subclass the control and set the SRE restriction.
    _Restrict_Edit(GUICtrlGetHandle(-1), SRE_Array, "InCorrect Syntax.")
    If @error Then MsgBox($MB_ICONERROR, "Error Code: " & @error, "Extended: " & @extended)

    GUISetState()

    Do
        Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;unsubclass the control
    _Restrict_Edit(GUICtrlGetHandle(-1))

EndFunc   ;==>_Main

Func SRE_Array($hEdit, $s_CurrentText)

    ;return an non-array non zero to block processing
    ;return zero to block restriction

    Local $aPatterns[3][2] = [ _
            ["(^|(?<=/\d{2}),)[mpson]?\d*(/|$)", True], _                       ;here True signifies +ve match, the string should match the pattern
            ["((\D)\2|/\d{3}|/\d?\D|/\d{2}[^,]|(?<=\D)/)", False], _            ;here False signifies -ve match, the string should NOT match the pattern
            ["[^mpson\d,/]", False]]

    ;Lets decode the above patterns
    #cs
        First Pattern +ve match
            1st Capturing group
                (^|(?<=/\d{2}),) : by start of string or comma( that too should be preceeded by a slash and two digits [look-behind assertion])

            [mpson]? : if present should be preceeded by 1st capturing group.

            \d* : any no. of digits

            2nd Capturing group
                ((/|$) : Either the end of the string, or a slash

            If the above pattern is not satisfied, processing is blocked.

        Second Pattern -ve match
            1st Capturing group
                ((\D)\2|/\d{3}|/\d?\D|/\d{2}[^,]) : consists of five different patterns nested. When either of the three is satisfied the pattern is matched
                1st NestedPattern
                    (\D)\2 : second capturing group, the first char is any non-digit, the second char is the same non-digit
                2nd NestedPattern
                    /\d{3} : after slash three digits are present.
                3rd NestedPattern
                    /\d?\D : after slash a non-digit is there or after slash a digit and then a non digit is present
                4th NestedPattern
                    /\d{2}[^,] : after slash two digits and anything other than comma is present.
                5th NestedPattern
                    (?<=\D)/ : slash preceeded by any non-digit

            If the above pattern is satisfied, processing is blocked.

        Third Pattern -ve match
            [^mpson\d,/] : match anything other than     m p s o n digit , /
            if the above is satisfied, processing is blocked
    #ce

    ;You can also block processing using this function.
    ;Say you don't want characters to exceed 20 then
    If StringLen($s_CurrentText) > 20 Then Return 1

    Return $aPatterns

EndFunc   ;==>SRE_Array

Though the straight away method is more simple and better conceptualized with nested conditionals, it modifies as follows

#include <GUIConstants.au3>
#include <RestrictEdit.au3>
#include <MsgBoxConstants.au3>

#cs
    [0]|m121/12,
    [1]|1231/12,
    [2]|p1/12,
    [3]|2/13,
    [4]|s1/14,
    [5]|o121/10
#ce

_Main()

Func _Main()

    #cs Pattern in text that should follow

        the first character can be any of 'm' 'p' 's' 'o' 'n' or a no. of digits
        followed by a "/" and then followed by two digits.
        Then if comma again the above pattern is expected otherwise, if EOL the pattern is satisfied.

    #ce

    ;our main GUI
    GUICreate("Restrict Edit | Phoenix XL", 200, 70)
    GUICtrlCreateLabel("Test", 10, 10, 200, 30)
    GUICtrlCreateInput("", 10, 30, 180, 20)

    ;subclass the control and set the SRE restriction.
    _Restrict_Edit(GUICtrlGetHandle(-1), SRE_Array, "InCorrect Syntax.")
    If @error Then MsgBox($MB_ICONERROR, "Error Code: " & @error, "Extended: " & @extended)

    GUISetState()

    Do
        Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;unsubclass the control
    _Restrict_Edit(GUICtrlGetHandle(-1))

EndFunc   ;==>_Main

Func SRE_Array($hEdit, $s_CurrentText)

    ;return an non-array non zero to block processing
    ;return zero to block restriction

    Local $aPatterns[1][2] = [ ["^([mpson]?(?(?=\d+)\d+(?(?=/)/(?(?=\d)\d{0,2}(,|$)|$)|$)|$))*$", True]]

    Return $aPatterns

EndFunc   ;==>SRE_Array

Regards :)

Phoenix XL

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

First I want to thank you.

Now it works excelent.


I rember that I need to restrict more complicated pattern

Here is an example what I want to achieve:
#include <array.au3>
$sText = 'm121/12,1231/12,p1a/12,2/13,s1/14,o121/10'
$aItems = StringRegExp($sText,'[mpson]?\d+[a-zA-Z]{0,3}\/\d\d,?',3)
_ArrayDisplay($aItems)

so I modyfied example by using this:

Func SRE_Array($hEdit, $s_CurrentText)

    ;return an non-array non zero to block processing
    ;return zero to block restriction

    Local $aPatterns[1][2] = [ ["^([mpson]?(?(?=\d+)\d+[a-zA-Z]{0,3}(?(?=/)/(?(?=\d)\d{0,2}(,|$)|$)|$)|$))*$", True]]

    Return $aPatterns

EndFunc   ;==>SRE_Array

And now it works perfectly, at least temporarily, I think it works perfectly ;)

Again, many thanks for your help.

 

Best Regards

mLipok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Hi

please add inside Func _Restrict_Edit($ControlHwnd, $pFunc = "", $s_ToolTip = "")

Local declaration for 

Local $Index = _ArraySearch($ai_ControlHwnd, $ControlHwnd)

Cheers

mLipok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

I am not very knowledge with RegEx expressions so I am having difficulty using the Restric Edit UDF to control limit the user to a HH:MM am/pm formatted entry.

Is there a source of examples? that I would be able to model after?

For the purposes of REstrict Edit what would the correct regex string be?

Ian

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  
Followers 0

  • Similar Content

    • ISI360
      By ISI360
      Hi!

      I need a little bit help from some RegEx experts please:
      I would make my ISN AutoIt Studio faster when generating the scripttree. And what would be better to do this via regex?
      Problem is i am not really good at this regex stuff. So maybe someone could help me here.
       
      The challange is to get all Global Variables from a script via RegEx in a Array.
      Here is a example script with some tests:
      Global $Var1 = 1234 Local $Local_Var = 1234 $Ignore_me_too = 1234 Global $Var2 = 1234, $var3 = 1242 Global $ahIcons[30], $ahLabels[30] Global Const $Var4 = iniread($inivar1,"jj","jj","") , $var5= iniread($inivar2,"jj","jj","") Global $Var_String = "was" Global $Array_Test[16] = [1,15,16,0,31,15,25,15,25,30,8,30,8,15,1,15] Global Enum $MARGIN_SCRIPT_NUMBER = 0, $MARGIN_SCRIPT_ICON, $MARGIN_SCRIPT_FOLD Global Const $Delim = '\', $Delim1 = '|' Global $hard1 = "a", _ $hard2 = "b", _ $hard3 = "c"  
      The returning array should look like this:
      $Var1 $Var2 $var3 $Var4 $var5 $Var_String $Array_Test $MARGIN_SCRIPT_NUMBER $MARGIN_SCRIPT_ICON $MARGIN_SCRIPT_FOLD $Delim $Delim1 $hard1 $hard2 $hard3  
      I already made some success with a expression i found in the SciTE Jump Tool:  (\$\w+)(?:[\h\[.=+*/^,)\-])?
      This nearly returns the perfect results. But it does not check if it´s a global variable (with the const and enum options) and also returns variables in commands (for example $inivar1)
      I also found this regex: (?im:^(?=Global|Const|Enum|Static)(?:Global)?\h*(?:Const|Enum|Static)?(?:(?<=Enum)\h+Step\h+[+*-]\d+)?\h*)([^\r\n .\=]+)
      This returns also usefull results...but trying to understand this explodes my head

      Maybe someone can help me here?
      Thanks in advance!
    • TheAutomator
      By TheAutomator
      Can anyone tell me why this isn't working?..
      #include <array.au3> $regexp = StringRegExp("test 'a b c'", "'([^']|'')*'|\S+", 3) _ArrayDisplay($regexp) trying to split this "test 'a b c'  'some other '' test'' ...'" into:
      0: test
      1: 'a b c'
      2: ...
      but it gives me:
      0: test
      1: c
    • nacerbaaziz
      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
    • anthonyjr2
      By anthonyjr2
      Hi guys,
      I am pretty bad with regex, and am having some trouble trying to come up with an expression for a certain type of string. Basically I want to be able to tell if a string is of the format:
      AA#####A
      Where the A's are any letter from A-Z and the #'s are any digit from 0-9.
      I've been playing around with a regex tester online for a while but I can't really seem to grasp the concept very well. Could anyone give me any tips?
      This isn't exactly an AutoIt specific question which is why I didn't post it in General Help & Support.
    • tezhihi
      By tezhihi
      I have a file (see attached file) with a string all line and this problem on here is I want to separate all $00:, $03:, $10:, $20:, $25:, $30:, $40:, $45:, $110:, $115:, $120: and $T. It's mean that each $ with value start a new line ( a new paragraph). I tried with Regular Expression in notepad++ ex:
      Find ($00:, $01:, $03: and so on) with regex (\$)([0-9]+): and replace is \r\n\1\2 (I think \r\n is @CRLF (not sure :() ) Find $T with regex (\$T)(.*?)(\$T) and replace is \1\2\r\n\3 When I try these regex to replace in notepad on StringRegexReplace the results is incorrect . I have read some example simple about regex. Please advise me how to do that with some example on autoit . The result will be in attached photo. Thanks 
      ahihi.txt