Jump to content

Easy Email Validation

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
kresh7

kresh7

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 661 posts
Hi All today i will show you a Funtion a made to validate email addresses in a string ok im not good at making tutorials so i hope you understand the most :D

ok the funtion looks like this


Public Function ValEmail(mail As String)

If Left(mail, 1) = "@" Then

GoTo NotValide

ElseIf Right(mail, 1) = "@" Then

GoTo NotValide

ElseIf InStr(1, mail, "@") = False Then

MsgBox "The @ is Missing!"

ElseIf InStr(1, mail, ".") = False Then

GoTo NotValide

ElseIf Right(mail, 1) = "." Then

GoTo NotValide

ElseIf Left(mail, 1) = "." Then

GoTo NotValide


'Not Valide

NotValide:

MsgBox "This is Not a Valide Email Address!"

End If

End Function


first part of the funtion like u see is

If Left(mail, 1) = "@" Then

GoTo NotValide


So this part looks for the @ on the first place of the string if the string is in the format @somthing
then its not valide so that the funtion calls the goto funtion and moves to NotValide


Next Part like you see is

ElseIf Right(mail, 1) = "@" Then

GoTo NotValide
its the same as above but this looks from the right if the first char is a @ its again a Invalide Email and again
we call goto

Next Part is

ElseIf InStr(1, mail, "@") = False Then

MsgBox "The @ is Missing!"
This is a easy if stament we use the instr funtion to make a bool statment dont know the right word for it
in english hope you know what i mean so if the instr funtion returns false we know that the @ is missing
and this is again not a valide email address and we then call a msgbox to tell that the @ is missing

Next Part is

ElseIf InStr(1, mail, ".") = False Then

GoTo NotValide
This is again a bool statment that looks for what the funtion returns if instr funtion returns false
we know that a . is missing so its not a valide email address if instr returns a true the . is present so it
an valide email :D **** im not good at making tutorials anyway lets continue

Next Part is

ElseIf Right(mail, 1) = "." Then

GoTo NotValide

ElseIf Left(mail, 1) = "." Then

GoTo NotValide
ive combined both statments here this do just like the first and second part in the tutorial it looks if the first from
right or first from left is a . if yes its not a valide email address.

last part is


NotValide:

MsgBox "This is Not a Valide Email Address!"

End If
This is the error code in case @ is first symbol from left or right or . is first symbol from left or right

Ok wow i never make a tutorial ok this funtion is just a basic one did it within 10 minutes but thought its
worth to post it Copyright of this Funtion NanoXcore thats me with dren,egzon,elban,limi :D
Posted Image

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Nice job. +rep
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
kresh7

kresh7

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 661 posts
I forggot to tell how to use the funtion ok like u see we have an a declaration and also a request we declare
(mail As String) mail as string and also request it so to use it simply use this example

ValEmail(text1.text)
Posted Image

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Very nice! +rep.

#5
Egz0N

Egz0N

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,034 posts
nice one bro .. and +rep indeed .. :)

#6
mendim.

mendim.

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,393 posts
Great Job .. +rep :)