Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

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

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
m0tSiE
Asked:
m0tSiE
1 Solution
 
Wayne Taylor (webtubbs)Commented:
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
 
TechTiger007Commented:
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
 
Wayne Taylor (webtubbs)Commented:
But that's the point. We don't want spaces after the email address, so using Trim() will not catch them.
0
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!

 
jpaulinoCommented:
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
 
TechTiger007Commented:
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
 
m0tSiEAuthor Commented:
Cheers mate :D
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now