saldous Posted August 26, 2009 Share Posted August 26, 2009 I've got the following code and I'm pretty sure I'm 99% there, but it isn't working and so I'm looking for help. Any ideas what I've done wrong? I don't get either message pop-up at the moment. thanks. $Form1 = GUICreate("Check if entered email address is valid", 429, 218, -1, -1, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) $EmailInput = GUICtrlCreateInput ("", 184, 23, 217, 21) $ExitButton = GUICtrlCreateButton("Exit", 104, 176, 75, 25) $Check = GUICtrlCreateButton("Check if valid", 240, 176, 75, 25, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP)) $Label1 = GUICtrlCreateLabel("Enter an email address:", 32, 24, 145, 17) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select ; Exit if the user closes the dialogue box or clicks on Exit button Case $msg = $GUI_EVENT_CLOSE Or $msg = $ExitButton Exit Case $msg = $Check Call ("_IsVailidEmail") EndSelect WEnd Func _IsVailidEmail($EmailInput) If StringRegExp($EmailInput, "^([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 MsgBox(4096,"Error", "Invalid email address entered.") MsgBox(4096,"ok", "Valid email address") EndFunc Link to comment Share on other sites More sharing options...
jvanegmond Posted August 26, 2009 Share Posted August 26, 2009 (edited) Don't .. use .. Call .. for .. this!!!! With that out of the way, here's what you did wrong: 1. You never read the email from the GUI element 2. You never passed the read email to the IsValidEmail method. While 1 $msg = GUIGetMsg() Select ; Exit if the user closes the dialogue box or clicks on Exit button Case $msg = $GUI_EVENT_CLOSE Or $msg = $ExitButton Exit Case $msg = $Check $email = GUICtrlRead($EmailInput) _IsVailidEmail($email) EndSelect WEnd P.S. you also wrote _IsVailidEmail wrong. Edited August 26, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
saldous Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks for your help. I'm still a bit stuck though, when I enter a valid email it now gives me both messages: While 1 $msg = GUIGetMsg() Select ; Exit if the user closes the dialogue box or clicks on Exit button Case $msg = $GUI_EVENT_CLOSE Or $msg = $ExitButton Exit Case $msg = $Check $email = GUICtrlRead($EmailInput) _IsValidEmail($email) EndSelect WEnd 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 MsgBox(4096,"ok", "Valid email address.") MsgBox(4096,"", "Error, invalid email address") EndFunc I tried putting "else" infront of the second msgbox but it doesn't like it. Think I've been looking at this too long and my brain is confused! Link to comment Share on other sites More sharing options...
trancexx Posted August 26, 2009 Share Posted August 26, 2009 You need to rest. Leave it as it is now and continue when you are fresh. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AoRaToS Posted August 26, 2009 Share Posted August 26, 2009 (edited) Thanks for your help. I'm still a bit stuck though, when I enter a valid email it now gives me both messages: While 1 $msg = GUIGetMsg() Select ; Exit if the user closes the dialogue box or clicks on Exit button Case $msg = $GUI_EVENT_CLOSE Or $msg = $ExitButton Exit Case $msg = $Check $email = GUICtrlRead($EmailInput) _IsValidEmail($email) EndSelect WEnd 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])\]){:content:}quot;) Then MsgBox(4096,"ok", "Valid email address.") MsgBox(4096,"", "Error, invalid email address") EndFunc I tried putting "else" infront of the second msgbox but it doesn't like it. Think I've been looking at this too long and my brain is confused! 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])\]){:content:}quot;") Then MsgBox(4096,"ok", "Valid email address.") Else MsgBox(4096,"", "Error, invalid email address") EndIf EndFunc Try it this way... Edited August 26, 2009 by AoRaToS s!mpL3 LAN Messenger Current version 2.9.9.1 [04/07/2019] s!mpL3 LAN Messenger.zip s!mpL3 Link to comment Share on other sites More sharing options...
saldous Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks AoRaToS but that doesn't work, it throws up all sorts of errors when I do that, I already tried the same thing. Link to comment Share on other sites More sharing options...
AoRaToS Posted August 26, 2009 Share Posted August 26, 2009 (edited) What kind of errors does it show? Did you try it all on one line, like this? 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])\]){:content:}quot;") Then MsgBox(4096,"ok", "Valid email address.") Else MsgBox(4096,"", "Error, invalid email address") EndIf EndFunc Edited August 26, 2009 by AoRaToS s!mpL3 LAN Messenger Current version 2.9.9.1 [04/07/2019] s!mpL3 LAN Messenger.zip s!mpL3 Link to comment Share on other sites More sharing options...
saldous Posted August 26, 2009 Author Share Posted August 26, 2009 ok, putting it all on one line has got rid of the error, it was an error about multi line but I couldn't work out where. It also gave a syntax error on the Else command, no idea why, error has now gone BUT... Using your version above always gives the output that the email address entered is invalid, even when it should be correct. No matter what I type it gives the invalid response. The formula had got broken, I've fixed it below. Now working great, thank you all >_< 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 MsgBox(4096, "", "Valid email address.") Else MsgBox(4096, "", "Error, invalid email address") EndIf EndFunc Link to comment Share on other sites More sharing options...
AoRaToS Posted August 26, 2009 Share Posted August 26, 2009 (edited) Glad you worked it out... I knew that :content:}quot; wasn't supposed to be there...The tags were to blame >_ Edited August 26, 2009 by AoRaToS s!mpL3 LAN Messenger Current version 2.9.9.1 [04/07/2019] s!mpL3 LAN Messenger.zip s!mpL3 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