Solved

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

Posted on 2008-10-27
6
211 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now