Email regular expression

S

shapper

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:
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)
....

How should I changed by regular expression to accomplish this?

Thanks,
Miguel
 
S

shapper

"\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
 
P

Peter Bradley

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"
"\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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top