Email regular expression

Discussion in 'ASP .Net' started by shapper, Mar 14, 2007.

  1. shapper

    shapper Guest

    Hello,

    I have a regular expression to validate email addresses:
    "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

    Now I need to force all emails to be from a given domain, for example,
    accept only:



    ....

    How should I changed by regular expression to accomplish this?

    Thanks,
    Miguel
     
    shapper, Mar 14, 2007
    #1
    1. Advertising

  2. "\w+([-+.]\w+)*@MyDomain\.com" ?
     
    Sergey Gorbachev, Mar 14, 2007
    #2
    1. Advertising

  3. shapper

    shapper Guest

    On Mar 14, 2:20 pm, "Sergey Gorbachev" <> wrote:
    > "\w+([-+.]\w+)*@MyDomain\.com" ?


    But I don't want MyDomain.com to be case sensitive.
    Any variation would be accepted. for example:
    MyDomain.Com
    mydomain.com
    MYDOMAIN.COM

    Does not really matter

    Thanks,
    Miguel
     
    shapper, Mar 14, 2007
    #3
  4. A quick Google gives:

    Options
    Another approach to handling case insensitivity is to use the IgnoreCase
    regex option. Options alter the overall regex matching behavior and, you
    guessed it, IgnoreCase turns off regex's default case sensitivity. The
    IgnoreCase option can be specified by prepending the short-form of the
    option 'i' in a special construct at the beginning of the regex, like so:

    (?i)coolThis inline syntax applies the option to an entire regex. However,
    an alternative syntax allows you to apply an option to either the whole
    expression or a subexpression:

    (?i:c)ool
    (see http://www.ddj.com/dept/windows/184416603)Or you could try:Using the
    Regex ClassAlmost anything you do with regular expressions in .NET starts
    out by defining a Regex instance for the regular expression of interest,
    like this (where pattern is your regular expression):Dim re As New
    RegEx(pattern)
    Another Regex constructor lets you set options:Dim re As New RegEx(pattern,
    options)
    The available options are represented in the RegexOptions enumeration. The
    options you are most likely to use are explained in Table 2. For the others
    you can refer to the Visual Studio documentation. To set a single option,
    pass it to the Regex constructor:Dim re As New RegEx(pattern,
    RegexOptions.IgnoreCase)
    To set two or more options, combine them with Or:Dim re As New
    Regex(pattern, RegexOptions.IgnoreCase Or RegexOptions.RightToLeft)
    Table 2. RegexOption members.Member Description IgnoreCase Specifies
    case-insensitive matching. The default is case-sensititve ("a" does not
    match "A", etc.). Multiline Multiline mode. The metacharacters ^ and $
    will match the beginning and end, respectively, of any line and not just the
    beginning and end of the entire input string (the default). RightToLeft
    Specifies that the search will be performed right-to-left rather than the
    default left-to-right. SingleLine Single line mode. Changes the meaning of
    the period (.) metacharacter so that it matches any character including the
    newline \n. By default it matches any character except the newline.
    from:http://www.devsource.com/article2/0,1895,2087373,00.aspPeter"shapper"
    <> wrote in message
    news:...
    > On Mar 14, 2:20 pm, "Sergey Gorbachev" <> wrote:
    >> "\w+([-+.]\w+)*@MyDomain\.com" ?

    >
    > But I don't want MyDomain.com to be case sensitive.
    > Any variation would be accepted. for example:
    > MyDomain.Com
    > mydomain.com
    > MYDOMAIN.COM
    >
    > Does not really matter
    >
    > Thanks,
    > Miguel
    >
     
    Peter Bradley, Mar 14, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,355
  2. Linus Nikander

    Email regular expression validator

    Linus Nikander, Sep 19, 2003, in forum: Java
    Replies:
    2
    Views:
    12,258
    Roedy Green
    Sep 19, 2003
  3. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    873
    Alan Moore
    Dec 2, 2005
  4. GIMME
    Replies:
    3
    Views:
    12,025
    vforvikash
    Dec 29, 2008
  5. Lad
    Replies:
    2
    Views:
    352
    Tim Roberts
    Sep 27, 2006
Loading...

Share This Page