Sign in to follow this  
Followers 0
saldous

Check if an email address is valid

9 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Manadar

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

You need to rest. Leave it as it is now and continue when you are fresh.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites

Thanks AoRaToS but that doesn't work, it throws up all sorts of errors when I do that, I already tried the same thing.

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Glad you worked it out... I knew that :content:}quot; wasn't supposed to be there...The tags were to blame >_

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
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
Sign in to follow this  
Followers 0