# How to force a minimum number of characters in InputBox?

## Recommended Posts

Hi, I hope someone can help me here:

When using InputBox you can set a maximum number of characters that can be entered, but I can't find a way to set a minimum number, is this possible?

Also, for example I'm asking a user to enter their email address, but I have no way to check what is entered follows an email address format, e.g does the text entered contain an "@".

Thank you for any help.

##### Share on other sites

If you are using a GUI then GUICtrlSetLimit() will help you here.

Edit:

Also, if I'm not mistaken, I've posted a _IsValidEmail() function before...

Edit2:

Yes, here it is:

http://www.autoitscript.com/forum/index.ph...st&p=301465

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Excellent, thanks SmOke N. I can't get it to work though... Here is my code:

CODE

400, -1)

Func _IsVailidEmail(\$email)

If StringRegExp(\$email, "^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|" & _

"((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])\$") Then Return 1

Return SetError(1, 0, 0)

If @error = 1 Then

else

Endif

EndFunc

What have I done wrong? I don't seem to be getting an error when it fails the check, neither of my message boxes appear.

Edited by saldous

anyone?

##### Share on other sites

You never actually called the function:

```; User enters email address
400, -1)
If _IsValidEmail(\$email) Then
Else
EndIf

Func _IsValidEmail(\$email)
If StringRegExp(\$email, "^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|" & _
"((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])\$") Then Return 1
Return SetError(1, 0, 0)
EndFunc```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Ah ha, I get ya, thanks for fixing this, it works perfectly!

##### Share on other sites

How about making an input box with a minimum number of characters to be entered though? i can set a max, but not a min. I need to to have a min of 6.

##### Share on other sites

How about making an input box with a minimum number of characters to be entered though? i can set a max, but not a min. I need to to have a min of 6.

Make a GUI.

Edit:

I already did an _InputBox GUI and I found it:

```#include <guiconstants.au3>
MsgBox(0, 'Info', _InPutBoxEx('My Input Box'))
MsgBox(0, 'Info', _InPutBoxEx('My Input Box', 'Some Text', 300))

Func _InPutBoxEx(\$sTitle, \$sText = '', \$iWidth = 200, \$iHeight = 75, \$iOnTop = 1, \$nInStyle = -1, \$nInStyleEx = -1)
Local \$aCID[5], \$iY = 0, \$sRead
If \$iWidth < 175 Then \$iWidth = 175
If \$iHeight < 75 Then \$iHeight = 75
If \$sText <> '' Then \$iY = 20
Local \$hGUI = GUICreate(\$sTitle, \$iWidth, \$iHeight + \$iY)
If \$sText <> '' Then \$aCID[1] = GUICtrlCreateLabel(\$sText, 10, 10, \$iWidth - 20, 20, \$ES_CENTER)
\$aCID[2] = GUICtrlCreateInput('', 10, 10 + \$iY, \$iWidth - 20, 20, \$nInStyle, \$nInStyleEx)
\$aCID[3] = GUICtrlCreateButton('OK', ((\$iWidth - 150) / 2), 40 + \$iY, 75, 25, \$BS_DEFPUSHBUTTON)
\$aCID[4] = GUICtrlCreateButton('Cancel', ((\$iWidth - 150) / 2) + 80, 40 + \$iY, 75, 25)
WinSetOnTop(\$hGUI, '', \$iOnTop)
GUISetState()
While 1
Switch GUIGetMsg()
Case - 3, \$aCID[4]
GUIDelete(\$hGUI)
Return ''
Case \$aCID[3]
GUIDelete(\$hGUI)
EndSwitch
WEnd
EndFunc```
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Thank you, but I can't get this to work, I can enter less than 6 characters and it still accepts it.

##### Share on other sites

Thank you, but I can't get this to work, I can enter less than 6 characters and it still accepts it.

I guess the thought of you trying to mod it yourself isn't actually an option?
```#include <guiconstants.au3>
MsgBox(0, 'Info', _InPutBoxEx('My Input Box'))
MsgBox(0, 'Info', _InPutBoxEx('My Input Box', 'Some Text', 300))

Func _InPutBoxEx(\$sTitle, \$sText = '', \$iWidth = 200, \$iHeight = 75, \$iOnTop = 1, \$nInStyle = -1, \$nInStyleEx = -1)
Local \$aCID[5], \$iY = 0, \$sRead
If \$iWidth < 175 Then \$iWidth = 175
If \$iHeight < 75 Then \$iHeight = 75
If \$sText <> '' Then \$iY = 20
Local \$hGUI = GUICreate(\$sTitle, \$iWidth, \$iHeight + \$iY)
If \$sText <> '' Then \$aCID[1] = GUICtrlCreateLabel(\$sText, 10, 10, \$iWidth - 20, 20, \$ES_CENTER)
\$aCID[2] = GUICtrlCreateInput('', 10, 10 + \$iY, \$iWidth - 20, 20, \$nInStyle, \$nInStyleEx)
\$aCID[3] = GUICtrlCreateButton('OK', ((\$iWidth - 150) / 2), 40 + \$iY, 75, 25, \$BS_DEFPUSHBUTTON)
\$aCID[4] = GUICtrlCreateButton('Cancel', ((\$iWidth - 150) / 2) + 80, 40 + \$iY, 75, 25)
WinSetOnTop(\$hGUI, '', \$iOnTop)
GUISetState()
While 1
Switch GUIGetMsg()
Case - 3, \$aCID[4]
GUIDelete(\$hGUI)
Return ''
Case \$aCID[3]
GUIDelete(\$hGUI)
MsgBox(262144 + 16, 'Error', 'You have entered too many characters.')
MsgBox(262144 + 16, 'Error', 'You did not enter enough characters.')
EndIf
EndSwitch
WEnd
EndFunc```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...