Jump to content

Restrict text in an input based on a RegExp - live testing while typing


peethebee
 Share

Recommended Posts

Hi!

I did this UDF for me (and you :P ). It tests while typing if the text entered to an input filed (should work with edit too) is atm fitting into a given RegExp or if it still can fullfill it.

How to use:

To start it up, you use:

_RegEx_RestrictControl_setup (20) ; prepare for up to 20 Controls to restrictoÝ÷ Ù'­¶)àj·¬¶¸¶*'¢v¢{k¢X¬vÞjdz&¬¶¬jëh×6$inp = GUICtrlCreateInput("", 10, 10, 100, 20)
_RegEx_RestrictControl_add ($inp, "^[a-z]{0,10}$") ; up to 10 letters
$inp2 = GUICtrlCreateInput("", 10, 200, 100, 20)
_RegEx_RestrictControl_add ($inp2, "^[a-zA-Z_0-9]{1,20}@[a-zA-Z_0-9]{2,20}.[a-z]{2,4}$", "g@gm.de") ; e-mail-addressoÝ÷ Ø2¢ë{*.+Þ¶¢{k¢R~*ì¶Ø^Ø^­ë-®'-Ñz1¥©Ý«-jö¥Û-®)à~âµ8^½©bvËkxjvÞ¢h­µçb~Ø^EèƬ~ée~)eyÖ¥Ø^¶)Â¥zÜ©x~z-Ê ÷­+Ûay@Åi×lj|¬¹»-®)à¡ø­~º&¶Ûh¶ººÞ×(Úèlµìmjwç$²Ø^EèÆazp'vÜ¢êì±ì¨ºwvÚ"ÉnuëaÆ­¶­¢Ê«±Êâ¦Ö¬²é¢©Ý±Êâ¦Ö«z)íëçb­«­¢+Ø¥¹±ÕÅÕ½ÐíIÍÑÉ¥Ñ
½¹Ñɽ±IáÀ¹ÔÌÅÕ½ÐìoÝ÷ Ù8^~ée²«q殶­sc²ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ°£²TDbæÖS¢&W7G&7D6öçG&öÅ&VtWæS2£²FW67&Föã¢F2TDb6â&W7G&7BFRFWBGVBçFòçWB6öçG&öÇ2ÆfR£²vÆRGær&6VBöâvfVâ&VwVÆ"W&W76öâࣲ&WV&VÖVçC¢WFôB2ã"ãã÷"vW £²WF÷#¢VWFV&VRVWFV&VTv×æFRÂGG¢ò÷wwræWFöBæFR£²æ÷F6S¢&6VBöâ67&B'vg&÷7BâF2F&VC¢£²GG¢ò÷wwræWFöG67&Bæ6öÒöf÷'VÒöæFWç÷6÷wF÷3Ó3SSbf׶ÃÖwV&Vv7FW&×6p£°£²ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÐ   ¢6æ6ÇVFRfÇC´wV6öç7FçG2æS2fwC° ¤vÆö&Â6öç7Bb33cµtÕô4ôÔÔäBÒ¤vÆö&Â6öç7Bb33c´Tåô4ätRÒ3 ¤vÆö&Âb33c¶'&õõ&VtWõ&W7G&7D6öçG&öųճEФvÆö&Âb33c¶'&õõ&VtWõ&W7G&7D6öçG&öÅöEö6÷VçBÒ   £³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ°£²gVæ7FöâæÖS¢õ&VtWõ&W7G&7D6öçG&öÅ÷6WGW£²FW67&Föã¢6WG2WFRfVGW&W2öbF2TDb⣲&ÖWFW"2¢b33cµ÷&&5öÖö6öçG&öÇ2÷÷FöæÂÂFVfVÇB£²FVfæW2÷rÖç6öçG&öÇ2vâ&R6öçG&öÆÆVBBÖ×VУ²&WV&VÖVçB2¢F2TDbæ6ÇVFV@£²&WGW&âfÇVR2¢æöæRࣲWF÷"2¢VWFV&VP£°£³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓФgVæ2õ&VtWõ&W7G&7D6öçG&öÅ÷6WGWb33cµ÷&U÷&5öÖö6öçG&öÇ2Ò¢uT&Vv7FW$×6rb33cµtÕô4ôÔÔäBÂgV÷Cµõ&VtWõ&W7G&7D6öçG&öÅö6V6²gV÷C²¢&TFÒb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&U÷&5öÖö6öçG&öÇ5Õ³EТb33c¶'&õõ&VtWõ&W7G&7D6öçG&öÅöEö6÷VçBÒ¤VæDgVæ2³ÓÒfwCµõ&VtWõ&W7G&7D6öçG&öÅ÷6WGW  £³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ°£²gVæ7FöâæÖS¢õ&VtWõ&W7G&7D6öçG&öÅöF@£²FW67&Föã¢6WG2WFR6öçG&öÆÆærf÷"6öçG&öÂ⣲&ÖWFW"2¢b33cµ÷&U÷&5ö7G&Æ@£²BöbFR6öçG&öÂFò&RÖöæF÷&V@£²b33cµ÷&U÷&5÷&VvW÷GFW&ࣲ&VtWv62Fò&RgVÆÆfÆÆVB÷"gVÆÆfÆÆ&ÆP£²b33cµ÷&&5÷fÆE÷7G&ær÷FöæÂÂFVfVÇBgV÷C²gV÷C²£²fÆB7G&ærf÷"FW7Færb&VtW6â7FÆÂ&RgVÆÆfÆÆVBࣲ&WV&VÖVçB2¢F2TDbæ6ÇVFV@£²&WGW&âfÇVR2¢æöæRࣲWF÷"2¢VWFV&VP£°£³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓФgVæ2õ&VtWõ&W7G&7D6öçG&öÅöFBb33cµ÷&&5ö7G&ÆBÂb33cµ÷&&5÷&VvW÷GFW&âÂb33cµ÷&&5÷fÆE÷7G&ærÒgV÷C²gV÷C²¢b33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33c¶'&õõ&VtWõ&W7G&7D6öçG&öÅöEö6÷VçEÕ³ÒÒb33cµ÷&&5ö7G&Æ@¢b33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33c¶'&õõ&VtWõ&W7G&7D6öçG&öÅöEö6÷VçEÕ³ÒÒb33cµ÷&&5÷&VvW÷GFW&à¢b33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33c¶'&õõ&VtWõ&W7G&7D6öçG&öÅöEö6÷VçEÕ³%ÒÒb33cµ÷&&5÷fÆE÷7G&æp¢b33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33c¶'&õõ&VtWõ&W7G&7D6öçG&öÅöEö6÷VçEÕ³5ÒÒgV÷C²gV÷C°¢b33c¶'&õõ&VtWõ&W7G&7D6öçG&öÅöEö6÷VçB³Ò¤VæDgVæ2³ÓÒfwCµõ&VtWõ&W7G&7D6öçG&öÅöF@  £³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ°£²gVæ7FöâæÖS¢õ&VtWõ&W7G&7D6öçG&öÅö6V6°£²FW67&Föã¢çFW&æÂ&ö6W76ærgVæ7FöâÒæ÷BFò&R6ÆÆVBg&öÒ÷WG6FRb333°£²&ÖWFW"2¢²ââåУ²&WV&VÖVçB2¢F2TDbæ6ÇVFV@£²&WGW&âfÇVR2¢æöæRࣲWF÷"2¢VWFV&VRW6ærvg&÷7Bb33·2v÷&²2&62£°£³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓФgVæ2õ&VtWõ&W7G&7D6öçG&öÅö6V6²b33c¶væBÂb33c¶×6rÂb33c·u&ÒÂb33c¶Å&Ò¢Æö6Âb33c¶äæ÷Fg6öFRÒôv÷&Bb33c·u&Ò¢Æö6Âb33c¶äBÒôÆõv÷&Bb33c·u&Ò¢Æö6Âb33c¶7G&ÂÒb33c¶Å&Ð £·â×6t&÷ÂgV÷C²gV÷C²ÂT&÷VæBb33c¶'&õõ&VtWõ&W7G&7D6öçG&ö¢f÷"b33cµ÷&U÷&5öÒFòT&÷VæBb33c¶'&õõ&VtWõ&W7G&7D6öçG&öÂÂÒ¢bb33c¶äBÒb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&U÷&5öÕ³ÒFVà¢bb33c¶äæ÷Fg6öFRÒb33c´Tåô4ätRFVࢲ6V6²&VtWæB6WBFW@¢f÷"b33cµ÷&&5ö¢ÒFò7G&ætÆVâb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&U÷&5öÕ³%Ò¢b33cµ÷&U÷&5÷&VvW÷&W2Ò£·â×6t&÷ÂgV÷C·&VvW7G&ærgV÷C²ÂuT7G&Å&VBb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&&5öÕ³Òfײ7G&æuG&ÔÆVgBb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&U÷&5öÕ³%ÒÂb33cµ÷&U÷&5ö¢¢b7G&æu&VtWuT7G&Å&VBb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&&5öÕ³Òfײ7G&æuG&ÔÆVgBb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&U÷&5öÕ³%ÒÂb33cµ÷&U÷&5ö¢Âb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&&5öÕ³ÒFVâWDÆö÷¢b33cµ÷&&5÷&VvW÷&W2Ò¢æW@¢bb33cµ÷&&5÷&VvW÷&W2ÒFVࢲ6fR7G&ær2gV÷C¶vööBgV÷C²fÇVRf÷"ÆFW"&W6WGF&ÆG¢b33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&U÷&5öÕ³5ÒÒuT7G&Å&VBb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&&5öÕ³Ò¢VÇ6P¢²&W6WBFWBFòÆ7B¶æ÷vâvööBfÇVP¢uT7G&Å6WDFFb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&U÷&5öÕ³ÒÂb33c¶'&õõ&VtWõ&W7G&7D6öçG&öŲb33cµ÷&&5öÕ³5Ò¢VæD`¢VæD`¢VæD`¢æW@¢²&ö6VVBFRFVfVÇBWFöC2çFW&æÂÖW76vR6öÖÖæG2ࢲ÷RÇ6ò6â6ö×ÆWFRÆWBFRÆæR÷WBࢲb333²b333²b333²'WBöæÇb33µ&WGW&âb33²vF÷WBçfÇVRvÆÂæ÷B&ö6VV@¢²FRFVfVÇBWFöC2ÖÖW76vRâFRgWGW&Rb333²b333²b333°¢&WGW&âb33c´uTõ%TäDTdÕ4p¤VæDgVæ2³ÓÒfwCµõ&VtWõ&W7G&7D6öçG&öÅö6V6° £²VÇærgVæ7Föâ'vg&÷7@¤gVæ2ôv÷&Bb33c·¢&WGW&â&E6gBb33c·Âb¤VæDgVæ2³ÓÒfwCµôv÷&@ £²VÇærgVæ7Föâ'vg&÷7@¤gVæ2ôÆõv÷&Bb33c·¢&WGW&â&DäBb33c·Âdddb¤VæDgVæ2³ÓÒfwCµôÆõv÷&

Have fun with that one!

Full source of a little test app is attached.

peethebee

RestrictControlRegExp.au3

RestrictControlRegExp_test.au3

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Link to comment
Share on other sites

  • 2 years later...
  • 3 months later...

If you utilize this in a script that already has:

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

Then you need to comment out:

Global Const $WM_COMMAND = 0x0111
Global Const $EN_CHANGE = 0x300

In "RestrictControlRegExp.au3" or you will see this error:

C:\Program Files\AutoIt3\Include\RestrictControlRegExp.au3(15,34) : ERROR: $WM_COMMAND previously declared as a 'Const'
Global Const $WM_COMMAND = 0x0111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Include\RestrictControlRegExp.au3(16,32) : ERROR: $EN_CHANGE previously declared as a 'Const'
Global Const $EN_CHANGE = 0x300
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\All Users\Documents\New Folder\CSCfg0610.au3 - 2 error(s), 0 warning(s)

And should in not have a #include-once at the top?

As well, in "RestrictControlRegExp.au3", the Include for GUIConstants.au3 is unnecessary and or should be for GUIConstantsEX.au3. Additionally, adding in an include for WindowsConstants.au3 in the RestrictControlRegExp.au3, even if it is already included in the script you are using RestrictControlRegExp.au3 in, will prevent any warning messages.

Hope this helps anyone.

Edited by Zacam
Link to comment
Share on other sites

  • 2 years later...

I found this UDF and it met my needs. Unfortuantely once I rolled out the application to the lab, a problem cropped up. After the program has been up and running for a while (several hours), suddenly the user can no longer enter a string. The characters show up and disappear almost immediately (as if it is failing the regexp comparison).

Anyone else using this UDF experienced this? Here is the code snippet I am using.

$SampleID = GuiCtrlCreateInput("", 140, 80, 130, 20)
_RegEx_RestrictControl_add ($SampleID, "^[a-zA-Z0-9()-]{0,10}$") ; up to 10 letters
Link to comment
Share on other sites

  • 4 years later...

The regexp would be "\d+\.\d{2}". Nothat this makes the dot and the cents parts (2 digits) mandatory.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 3 years later...
  • Developers
1 hour ago, Acanis said:

Pretty useful! :)

 

Seriously? A thread of 2006 gets bumped by this post?
Please don't!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...