Solved

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

Posted on 2008-10-27
6
213 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

914 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

14 Experts available now in Live!

Get 1:1 Help Now