Specfic Email Address Validation using Regex - regex

I have a registration form where email address is needed.
I need to allow the email addresses that belongs only to domain("NAME"#Mobily.com.sa) this is for employees that working for "MOBILY"
Also we need to disallow the emails that is ( "NAME".c#mobily.com.sa ) where those emails that ends up with (.c) belongs to the contractors working for "Mobily".
The Idea is to allow the employees and disallow the contractors from registration.
Please Advise the proper REGEX to achieve this.

Use this:
var regEx = /^(\w+)#(mobily\.com\.sa)$/i;
In case you want to support name as "abc.def", do
var regEx = /^(\w+\.?\w+)#(mobily\.com\.sa)$/i;
Examples:
regEx.test("ab212121c#mobily.com.sa") //true
regEx2.test("ab212121.c#mobily.com.sa") //false

The following regex can have a everything as name except names ending with .c
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+(?!\.c).{2}#mobily\.com\.sa$/i
See here
https://regex101.com/r/6vgQbj/2

You can use a negative lookahead to prevent .c from occurring right before the #.
/[\w\.\+-]+?(?!\.c).{2}#mobily\.com\.sa/g
See the regex in action here:
https://regex101.com/r/i0Rg34/2

please use this:
[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+#mobily.com.sa

Related

Regex to match email id's in javascript?

Lets say I have something like this:
vin#text.com
jay#text.com
text#text.com
All these id's belong to #text.com, and I want to match just that, whether an id has a
#text.com
or not
for example:
vin#gmail.com is invalid
while
vin#text.com is valid
but
vin#text.com.com , vin#text.com#text.com are both invalid
there should not be any characters after #text.com but there can be as many as possible in the beginning
So, text.com can be treated as required after # for your scenario.
Simple regex could be
^[a-zA-Z0-9+_.-]+#text.com+$
Please have a look if this works for you.
Happy Coding!

I am using Regex for email validation EMAIL_PATTERN:/^(\w+([.]\w+)*#\w+([.]\w+)*\.\w+([.]\w+)*)$/,

I'm Following the below Example:
Email validation expression \w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)* allows empty spaces
I'm using EMAIL_PATTERN:
`/^(\w+([.]\w+)*#\w+([.]\w+)*\.\w+([.]\w+)*)$/`
with minor changes.
It is allowing me to enter the email as i want but i dont want "_" at the
starting of the email address. Example: _abc#gmail.com
How to solve this?
What regex google is using in gmail?
Use This
/^([a-zA-Z0-9]+([.][a-zA-Z0-9]+)#\w+([.]\w+)\.\w+([.]\w+)*)$/,

REGEX to match domain in email addresses

I'm currently using this very relaxed REGEX to validate email addresses:
(/(.+)#(.+)\.(.+){2,}/.test(emailAddress)
I believe that it only allows min1_allowsDots#min1_allowsDots.min2 - is this correct?
How should I modify it to match only a particular domain - anything# onlythisdomain.com?
TIA!
iSofia
(.+)#onlythisdomain\.(.+){2,}
This should do it.If .com is also fixed use
(.+)#onlythisdomain\.com
This simple RegEx basically says:
At least one character, then an "#", then literally "gmail.com".
If you change the domain to something else, it will not match.
var email = 'Godisgood#gmail.com';
var re = /.+\#gmail\.com/;
alert(email.match(re));
Maybe this could help you:
^[a-zA-Z0-9_.+-]+#(?:(?:[a-zA-Z0-9-]+\.)?[a-zA-Z]+\.)?
(company_domain1|company_domain2)\.ca$/g
It is a regex where you can validate the email including a specific domain such as
jhosh#doctorgroup.ca or jhosh#doctors.ca and it will match only if the email is ending with #doctorgroup.ca or #doctors.ca.

fetch email address that does not contain certain words from webpage

Please tell me how can I extract emails (1st match) that does not contain words 'ajax' and 'gif' within email address. Here's the basic regex that I have:
match = re.findall('([\w.-]+#[\w.-]+\.\w+)', q.read(), re.I)[0]
Thanks,
I think you want something like this,
\b(?!\S*(?:ajax|gif)\S*)([\w.-]+#[\w.-]+\.\w+)\b
DEMO

Regex for e mail id which will allow only spcific numbers of dots(1-5) after # the sign

People have discussed a lot on Regex for email validations.
I found many ideal regex for email id but all of them are validating email id having more than 2 dots
i.e.
sangram#ab.cd.ef.gh.ij.kl.mn.op
All regex are validating this email id which is not right.
its a wrong email id according to me, i understand there can be sub -sub -sub domains , but still more than 5 dots should not be allowed.
i want this thing to be controlled and only 1 to 5 dots can be entered after the # sign.
so how this can be done using regex ?
Thanks in advance.
i hope that stackoverflow will solve this problem for sure.
-Sangram
I'm not sure why you think there is a maximum on the number of subdomains possible in an email address.
In any case, it is pointless to try to perfectly match valid email addresses with a regex. No matter how baroque your regex, it will allow countless invalid email addresses through, since you don't know if a syntactically correct domain is an actual domain, or if a "correct" user name is actually accepting email.
Use this pattern:
/^[^# ]+#[^# ]+\.[^# ]+$/
and be done with it. More about this at humane email validation.
See if this can help. (Mind you it's is a reduced down validation)
\A[A-Za-z0-9._%+-]+#(?:[A-Za-z0-9-]+\.){1,5}[A-Za-z]{2,4}\Z
RFC 2822
Simplified version :
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?