I Want to implement multiple email validation with specific domain using regex separated by ;. Requirement is to allow only two email id separated by semicolon.
I tried regex
^([\w+-.%]+#domain+\.com[~]?){1,2}$
it works fine but it validates email followed by ; . It should work as below
1) abc#domain.com valid
2) abc#domain.com;abc1#domain.com valid
3) abc#domain.com; invalid
4) abc#domain.com;abc1#domain.com; invalid
How to do it using regex?
Try:
"^([\w+.%-]+?#domain\.com)(;([\w+.%-]+?#domain\.com))?$"
It consists of addres 1
([\w+.%-]+?#domain\.com)
and zero or one further addres
(;([\w+.%-]+?#domain\.com))?
"^...$" makes shure that there are no other characters around.
Group 1 and Group 3 will contain the addresses
Test here
Related
I have a long-form field ("Paragraph" type) in a Google Form. Users are expected to fill in any number of email addresses - at least one email, could be as many as 20-50 email addresses for some users.
I want to make sure that:
Each line is likely to be a valid email (by checking for a "#" character and a "." character)
Each line contains ONLY ONE email (by checking for "#" characters not separated by line breaks)
I know I can use the following string to check for two valid email addresses separated by a line break:
[a-zA-Z0-9_\.\+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-\.]+\n+[a-zA-Z0-9_\.\+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-\.]
However, this limits the user to submitting two (no more, no less) email addresses.
Is there a way to check for 1 email address per line, and allow anything from 1 to multiple emil addresses?
You could write the pattern with anchors and repeating 1 or more newlines followed by the same pattern.
^[\w.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+(?:\n+[\w.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+)*$
See a regex101 demo
I'm new to mailgun and I'm trying to create a filter for "Matching on variations of the recipient of the email". I want it to work just like gmail. Example:
jondoe#gmail.com, jon.doe#gmail.com and j.o.n.d.o.e#gmail.com are the same accounts. Basically I want to remove dots from addresses.
I also want to add option + at the end of address for forwarding purposes. Example: jonedoe+facebook#gmail.com.
This is a regex for adding + at the end but how do I remove the dots?
match_recipient("^chris\+(.*)#example.com$")
Actually I have this now:
(chris)(#example.com)|(^((.*\.)+.*)#example.com$)|(^(chris)\+(.*)#example.com$)
And this will match this variations:
chris#example.com
chris+#example.com
chris+d#example.com
chris+3#example.com
chris+d8#example.com
chri.s#example.com
c.hri.s#example.com
c.h.r.i.s+#example.com
c.h.r.i.s+2d#example.com
.chris#example.com
chris.#example.com
And won't match these (as it shouldn't):
ch5ris#example.com
cchris#example.com
chriu#example.com
chriOs#example.com
chbis#example.com
cchhrriiss#example.com
michael#example.com
The only issue now is that it matches names with dots at the beginning and at the end. How do I fix this now?
I want to match the emails in following texts,
uma#cs.stanford.edu - match
uma at cs.Stanford.edu - match
http://infolab.stanford.edu/~widom/yearoff.h
we
genale.stanford.edu
n <A href="mailto:cheriton#cs.stanford.edu - match
hola # kirti.edu - match
Now I want to capture 2 parts of email address only like (uma) and (cs.stanford) in the email uma#cs.stanford.edu.
My current pattern is :
(\w+)[(\s+at\s+)|(\s*#\s*)]+(\w+|\w+\.\w+).edu
But it matches the string - infolab.stanford.edu - which I don't want.
Can anybody suggest any modification on this?
As long as you understand that this regex doesn't verify the correctness of your email address, but merely acts as a quick first line of defense against malformed addresses, an easy fix to your regex is as follows:
([\w.]+)(?:\s+at\s+|\s*#\s*)(\w+|\w+\.\w+).edu
In particular your regex was missing addresses with usernames containing . (which for example my main email address uses), as well as had a messed up middle part (pretending it's a character class and something weird about letting it repeat??). You can see the results here: http://refiddle.com/2js1
Currently i am writing a software where a user can input more than one email in a input field separated by: ";"
Now i have a regex that validates the email but sadly enough doesn't work when i have more Emails in the input field when using the separation.
Has anyone ever created such a regex or is there anyone that is able to help me?
Thanx in advance and looking forward for a response.
Here is my Regex:
[a-zA-Z0-9_.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]{2,4}+(\;|)
Just put the pattern which matches the following emails inside a non-capturing group with a preceding ; and make it to repeat zero or more times.
^[a-zA-Z0-9_.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]{2,4}+(?:;[a-zA-Z0-9_.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]{2,4}+)*$
And one more thing is, you need to escape the dot.
Hi i have field called UserName into my MVC 3 Model. This propery could be valid email address or could be valid AlphaNumeric. How i can write Regex Express to check both things (Valid Email or Valid Alpha Numeric).
Valid Email Expresion which i am using is
"^[_a-zA-Z0-9\'-]+(\.[_a-zA-Z0-9\'-]+)*#[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(name))$"
Assuming that the alphanumeric string you want to match instead of an email address really is just A-Z and 0-9, you can take what you have already...
^[_a-zA-Z0-9\'-]+(\.[_a-zA-Z0-9\'-]+)*#[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(name))$
...and wrap it in parenthesis with a pipe to indicate it as an optional group...
^([_a-zA-Z0-9\'-]+(\.[_a-zA-Z0-9\'-]+)*#[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(name))|[a-zA-Z0-9]+)$
Which seems like an overly simplistic solution, give the work you have done so far, which makes me wonder if there is some catch to this???
if you want alpha numeric(must contain single alpha and single numeric) try this
(?=[0-9a-zA-Z]*[a-zA-Z][0-9a-zA-Z]*)(?=[0-9a-zA-Z]*[0-9][0-9a-zA-Z]*)(^[0-9a-zA-Z]+$)