CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Format text

  1. #1
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Format text

    How to check if string is in e-mail format and if it's not then text1 = "" when text1 lost focus



  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Format text

    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.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Format text

    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

  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Format text

    me 2

    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  5. #5
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Format text

    LIKE rocks!!! :-)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured