Solved

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

Posted on 2008-10-27
6
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 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