Email regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    #1

    Email regular expression

    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:
    john@MyDomain.c om
    andrew@MyDomain .com
    marysmith@MyDom ain.com
    ....

    How should I changed by regular expression to accomplish this?

    Thanks,
    Miguel

  • Sergey Gorbachev

    #2
    Re: Email regular expression

    "\w+([-+.]\w+)*@MyDomain\ .com" ?


    Comment

    • shapper

      #3
      Re: Email regular expression

      On Mar 14, 2:20 pm, "Sergey Gorbachev" <SergeGo...@ram bler.ruwrote:
      "\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

      Comment

      • Peter Bradley

        #4
        Re: Email regular expression

        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.Ig noreCase)
        To set two or more options, combine them with Or:Dim re As New
        Regex(pattern, RegexOptions.Ig noreCase Or RegexOptions.Ri ghtToLeft)
        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.c om/article2/0,1895,2087373, 00.aspPeter"sha pper"
        <mdmoura@gmail. comwrote in message
        news:1173883729 .301256.53870@l 75g2000hse.goog legroups.com...
        On Mar 14, 2:20 pm, "Sergey Gorbachev" <SergeGo...@ram bler.ruwrote:
        > "\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
        >

        Comment

        Working...