Learn how to a build a cloud-first strategyRegister Now

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

Regular Expression for EmailID

Hi,
I need a Regularexpression for EmailID.
somename@bkwsu.org. It can be anyname before@bkwsu.org.

Please let me know.

Thanks
0
KavyaVS
Asked:
KavyaVS
  • 5
  • 4
  • 3
  • +2
5 Solutions
 
käµfm³d 👽Commented:
I would think the following should suffice:

[^@ ]+@bkwsu.org\b

Open in new window

0
 
ozoCommented:
Actually, it is possible for [@ ] to be part of an email address, but bkwsu.org can ensure that it never uses such names
0
 
tel2Commented:
Are you happy for characters like comma to be accepted, KavyaVS?  I'm not sure if they are technically allowable.

TRS
0
Technology Partners: 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!

 
ozoCommented:
Technically, characters like comma are allowable, although bkwsu.org may have a policy of never using them.
0
 
KavyaVSAuthor Commented:
I am using VisualStudio 2010 and C#.I tried [^@ ]+@bkwsu.org\b as regex. But it is not working.

I changed it as "[^  ]+@bkwsu.org" as regex.is it correct for the following requirement.
The email can be anything before bkwsu.org but the domain should be @bkwsu.org

I tried different options .It is working.
I want to make sure whether it is ok or not.


Please let me know the changes.

Thanks.
0
 
käµfm³d 👽Commented:
It should be fine. I don't see why the previous version shouldn't work as well (unless, as ozo mentioned, you have recipients who actully have @ as a part of their username!).
0
 
KavyaVSAuthor Commented:
Hi kaufmed,
[^@ ]+@bkwsu.org\b  It is not even accepting TestEmail@bkwsu.org

Why?

As you said it's fine,I will use this "[^  ]+@bkwsu.org"

Thanks
0
 
Terry WoodsIT GuruCommented:
If it's just an escaping problem, it may need to be [^@ ]+@bkwsu.org\\b
but other than that, it should work for TestEmail@bkwsu.org

If it still doesn't, perhaps you should copy and paste some of the surrounding code for review.
0
 
Terry WoodsIT GuruCommented:
Strictly, kaufmed's pattern will also match the TestEmail@bkwsu.org part of TestEmail@bkwsu.org.nz or TestEmail@bkwsu.org.someotherdomain.com so this minor change might be worthwhile:

[^@ ]+@bkwsu.org(?![\\w.\\-])

Or if you're validating a string that just contains the value you're matching, and nothing else, then this would be simpler:

^[^@ ]+@bkwsu.org$
0
 
käµfm³d 👽Commented:
We would need to know the context of how you are using the expression. Either works fine for me. If it's a validation situation where you want to enforce that a user enter someone's email address as [anyone]@bkwsu.org, then I agree with Terry. I didn't go that route because I felt as if you were searching for email addresses in a block of text. In that case, either of the other methods should work.

e.g.

Screenshot
0
 
KavyaVSAuthor Commented:
I am not searching for email addresses in a block of text.I am just taking the value entered in a TextBox and comparing it with regex.

Now I am using this [^ ]+@bkwsu.org and it's validating fine. Do you want me to change it as
^[^@ ]+@bkwsu.org$ or is it ok with the one I am using.

Please let me know.

Thanks
0
 
käµfm³d 👽Commented:
If you are validating a TextBox, then yes it would be better to bound the values using the start of string ( ^ ) and end of string ( $ ) anchors.
0
 
tel2Commented:
...otherwise I expect you will find that addresses like the following will match (i.e. will be accepted as valid):
    @test@bkwsu.org
    test@bkwsu.org.nz
Test the above examples if you like.
0
 
KavyaVSAuthor Commented:
I tried them . They are not accepted.
@test@bkwsu.org
    test@bkwsu.org.nz


Thanks
0
 
KavyaVSAuthor Commented:
Thanks
0
 
tel2Commented:
> I tried them . They are not accepted.
Are you saying they are not accepted when you include the "^" & "$" in the regex, or exclude them?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now