Regular Expression - Allow White Spaces

Posted on 2009-12-17
Last Modified: 2012-06-27
I have an control using a regular expression for validation, it is for an email address.  It allows alphanumeric and also allows 1 character domain names.  

I need to modify it to also allow white spaces at the beginning and end of it (but not anywhere in the middle).  Not sure how to do this, I have tried and have failed miserably thus far.  

Here is the current expression which works as desired but new request for white spaces means it needs to be updated:

Public Const REG_EMAIL As String = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"

Thanks in advance, I hope someone can help.

Question by:kruegerste
    LVL 74

    Accepted Solution

    LVL 4

    Author Comment

    Awesome, thanks. Works perfect.  
    LVL 4

    Author Closing Comment

    Awesome, thanks. Works perfect.  
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    NP. Glad to help :)

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now