Click to See Complete Forum and Search --> : validate email address


catgirl78
March 17th, 2001, 09:10 PM
hi there, my VB application allow the user to enter his/her email address..how do i check whether the email that the user entered is of the right format...?? please help..thanks

coolbiz
March 17th, 2001, 11:50 PM
Well .. a valid email should at least be in this format username@domain.com, so you can use the sample code below to check:


function ValidateEmail(szEmail as string) as boolean
dim nInd as integer
dim bValid as boolean

bValid = false ' by default - not valid
nInd = instr(1, szEmail, "@") ' get the @
if (nInd > 0) then
' found the @ then check for .
nInd = instr(nInd, szEmail, ".") ' get the .
if (nInd > 0) then
' found - probably a valid email
bValid = true
end if
end if

ValidateEmail = bValid
end function




-Cool Bizs