Solved

Check text in text box ends with .co.uk?

Posted on 2008-10-27
6
214 Views
Last Modified: 2010-04-21
Hi,

Can someone please show me how to add a validation check to my textbox to make sure it ends with .co.uk when a button is pressed?

The reason for this is that i'm using an application to send emails, however the system i'm pulling the details from sometimes misses the end of the email address. Therefore this way, I can stop the emails from sending / give an error if the email address in SendTo.Text does not end in .co.uk.

Thanks,

Paul.
0
Comment
Question by:m0tSiE
6 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 22810730
Hi m0tSiE,

Use something like this....

    If Textbox1.Text.EndsWith(".co.uk") = False Then
        MsgBox("Invalid address. Must end with '.co.uk'")
    End Id

Regards,

Wayne
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22810742
just a small modification to avoid empty spaces at the end

  If Textbox1.Text.Trim().EndsWith(".co.uk") = False Then
        MsgBox("Invalid address. Must end with '.co.uk'")
    End Id
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22810751
But that's the point. We don't want spaces after the email address, so using Trim() will not catch them.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 48

Expert Comment

by:jpaulino
ID: 22810757
I also like to use this way because some users like to write with caps lock (down know why := ) :

If Me.Text.Trim.ToLower.EndsWith(".co.uk") Then
             ' ...
End If
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22810776
webtubbs, you are right. and combining the valid suggestion from jpaulino

dim emailid as string = Textbox1.Text.EndsWith(".co.uk").Trim() 'This variable should be used as recepient's email id
If emailid.ToLower().EndsWith(".co.uk") = False Then
        MsgBox("Invalid address. Must end with '.co.uk'")
    End Id
0
 

Author Closing Comment

by:m0tSiE
ID: 31510218
Cheers mate :D
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question