saldous Posted February 20, 2007 Share Posted February 20, 2007 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. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 20, 2007 Moderators Share Posted February 20, 2007 (edited) 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 February 20, 2007 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. Link to comment Share on other sites More sharing options...
saldous Posted February 20, 2007 Author Share Posted February 20, 2007 (edited) Excellent, thanks SmOke N. I can't get it to work though... Here is my code: CODE; User enters email address $email = InputBox("Email checker", "Please enter your email address", "", " M", _ 400, -1) ;is the email address valid? 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 msgbox(4096,"Invalid Email Address", "The email address you entered is not valid, please try again") else msgbox(4096,"Correct Email Address", "The email address you entered is OK") 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 February 20, 2007 by saldous Link to comment Share on other sites More sharing options...
saldous Posted February 20, 2007 Author Share Posted February 20, 2007 anyone? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 20, 2007 Moderators Share Posted February 20, 2007 You never actually called the function:; User enters email address $email = InputBox("Email checker", "Please enter your email address", "", " M", _ 400, -1) If _IsValidEmail($email) Then msgbox(4096,"Correct Email Address", "The email address you entered is OK") Else msgbox(4096,"Invalid Email Address", "The email address you entered is not valid, please try again") EndIf ;is the email address valid? 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. Link to comment Share on other sites More sharing options...
saldous Posted February 21, 2007 Author Share Posted February 21, 2007 Ah ha, I get ya, thanks for fixing this, it works perfectly! Link to comment Share on other sites More sharing options...
saldous Posted February 21, 2007 Author Share Posted February 21, 2007 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. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 21, 2007 Moderators Share Posted February 21, 2007 (edited) 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] $sRead = GUICtrlRead($aCID[2]) GUIDelete($hGUI) Return $sRead EndSwitch WEnd EndFunc Edited February 21, 2007 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. Link to comment Share on other sites More sharing options...
saldous Posted February 22, 2007 Author Share Posted February 22, 2007 Thank you, but I can't get this to work, I can enter less than 6 characters and it still accepts it. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 22, 2007 Moderators Share Posted February 22, 2007 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] $sRead = GUICtrlRead($aCID[2]) If StringLen($sRead) <= 10 And StringLen($sRead) >= 6 Then GUIDelete($hGUI) Return $sRead ElseIf StringLen($sRead) > 10 Then MsgBox(262144 + 16, 'Error', 'You have entered too many characters.') ElseIf StringLen($sRead) < 6 Then 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now