How to check if string is in e-mail format and if it's not then text1 = "" when text1 lost focus
Printable View
How to check if string is in e-mail format and if it's not then text1 = "" when text1 lost focus
Add folowing code to your form:
private sub text1_lostfocus()
dim intPos as string
dim isEmail as boolean
isEmail = false
'check for @ in text1 and get its position
intpos = instr(text1.text,"@")
if intpos > 0 then
' if there is a @ in the text
if instr(intPos,text1.text,".") > 0 then
'if there is a . after the @
isEmail = true
end if
end if
if not(isEmail) then
' if not a valid email
text1.text = ""
end if
End sub
Tom Cannaerts
[email protected]
The best way to escape a problem, is to solve it.
An even easier way :
If Text1.Text Like "*@*.*" then
MsgBox "OK"
else
MsgBox "not ok"
End If
- I must remember to start using the Like command more often!
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
me 2
Tom Cannaerts
[email protected]
The best way to escape a problem, is to solve it.
LIKE rocks!!! :-)