Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Inputbox data validation (5 characters or less)


  • Please log in to reply
4 replies to this topic
Xx7
  • Members
  • 674 posts
  • Last active: Mar 24 2015 10:48 PM
  • Joined: 19 Apr 2011

I would like to ensure that the inputbox string is 5 characters or less.  Isn't there a default option for this?? I would like it so that if the user tries to enter a 6th character, it won't show up.  Maybe a tooltip or something pops up that says input must be 5 or less characters.  I would also like the characters to be ONLY numerical, with a tooltip that pops up if the user tries to enter text.

 

Here's what I've been currently using, but I don't want a msgbox..

 

InputBox, search_term,,,, 250, 100
if (StrLen(search_term) > 5)
   MsgBox, string too long!


faqbot
  • Members
  • 997 posts
  • Last active:
  • Joined: 10 Apr 2012
Make a Gui with and Edit control http://www.autohotke...ntrols.htm#Edit and set the Limit and Number options.

More complex entry validation:
1 - jsherk function http://www.autohotke...n-edit-control/
2 - jballi edit library http://www.autohotke...e-2#entry432114

Sjc1000
  • Members
  • 572 posts
  • Last active: Mar 11 2017 11:41 AM
  • Joined: 06 Feb 2012

As an alternative to faqbot's response you can use the Input with L ( limit ) like L5 ( limit 5 )

 

and just have something to check if the data is a digit.. And if its not go back to the start and try again..

 

 

 

Start:
Input, Search_term, L5
If Search_term is not digit
{
MsgBox, Please only enter numbers
Goto, Start
}
MsgBox, %Search_term%

Sjc1000 - Insert inspirational quote here!

PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.

 


just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011
#NoEnv
Title := "Search Term"
MaxChars := 5
SetTimer, SetEditOptions, -20                ; call timer SetEditOptions once after 20 ms

InputBox, search_term, %Title%, ,, 250, 100

ExitApp

SetEditOptions:
If WinExist(Title . "ahk_class #32770") {    ; check for the input box
   SendMessage, 0x00C5, MaxChars, 0, Edit1   ; EM_LIMITTEXT -> accept up to MaxChars characters
   Control, Style, +0x2000, Edit1            ; ES_NUMBER    -> accept only digits
}
Return

 

But I'd prefer to use a GUI in this case, too.


Prefer ahkscript.org for the time being.


jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
Thanks for the idea/code just me. Just for fun, I will probably create an example for the Edit Library based on this concept. Like you, I will probably never use it (create a custom GUI instead) but it will be out there just in case someone needs it.