Regular expression validation contain .com at the end of Email - regex

I am working on the Regular Expression validation and validate on the email textbox.
But the condition is use enter valid email but at the end of email use .com only i use this
ValidationExpression="^\w+([-+.']\w+)*#abc.com$" it works but only for abc at the end of # .
But i need that use will enter any number or alphabet after # .
Thanks

You should not validate email addresses using regular expressions. You will most probably get it wrong.
To validate whether a string ends with .com, use this regex:
\.com$
That's it. Example in C#:
if (Regex.IsMatch(eMail, #"\.com$", RegexOptions.IgnoreCase))
But then, in C#, you could just write
if (eMail.EndsWith(".com", StringComparson.InvariantCultureIgnoreCase))

But i need that user will enter any number or alphabet after #
ValidationExpression = "^\w+([-+.']\w+)*#[A-Za-z\d]+\.com$"

Related

How to match username which is enclosed in special chars

I try to match the username of users on YouNow from a specific field.
I extracted this html, I try to extract the username _You Won
"\n\t\t\t\t\t\t14\n\t\t\t\t\t\t_You Won\n\t\t\t\t\t"
This is my regex attempt:
(\d+)[\\n\\t]+([\W\w]+[^\\n\\t"$])
This worked fine, first I match a number which is the level, then I match the username. However, if the username ends with either t or n then it does not get the last letter. So user game 1n would get cut down to game 1
Does someone know how I can fetch the username correctly?
Play it:
https://regex101.com/r/j8rufa/2
You could use Positive Lookahead at the end instead of [^\\n\\t"$].
Your code will be:
(\d+)[\\nt]+([\W\w]+(?=\\n\\t))
Demo: https://regex101.com/r/j8rufa/4
You can also use Positive Lookbehind to further enhance the code to ensure that the whole name is matched. For example, if the name is something like t_You Won, it will be matched without any issues:
(\d+)[\\nt]+(?<=\\t)([\W\w]+(?=\\n\\t))
Demo: https://regex101.com/r/j8rufa/6

Regular expression to validate comma separated email addresses

I am supposed to validate comma separated email addresses and avoid invalid patterns like
email..email#domain.com,
.email#domain.com,
email#domain.web,
email.#domain.com,
email#-domain.com,
email#domain.web,
email#111.222.333.44444
currently I am using following Regular expression
regex = /^((\w+([-+.']\w+)*#\w+([-.]\w+)*\.([a-zA-Z])+([-.]\w+)*)*([,])*)*$/
(custom regex rule as in validation-engine)
For which I can not use email#domain99.com which can be a valid email address in my case
Please suggest me suitable answer!
EDIT- regex = /^((\w+([-+.']\w+)*#\w+([-.]\w+)*\.([a-zA-Z])+([-.]\w+)*)* ([,])*)*$/ this expression miserably failed when I used ,, instead of , to separate the values. Suggest a way please.

A regular expression for using an email address as username?

Is there a regular expression out there for using a normal username OR an email address as a username? I would like a user to be able to enter their own username, or just use their email address as the username and I am unable to find any reliable information on how to achieve this properly. It would still have to pass validation as well, for example: if the user chooses to make their own username, it would have to abide by my policy for usernames, which limits them to starting with a letter or number, and no special characters, or if they enter an email, it would have to abide by the email rules(typical email rules). Anyone have a suggestion for this?
Try this regular expression:
/^(?:[A-Z\d][A-Z\d_-]{5,10}|[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4})$/i
The expression has two parts:
The first part validates a username. Feel free to optimize this part for matching you own policy. The regex here accepts username starting with a letter or a number. A username can't belonger than 11 characters. - and '_' are allowed.
The second part validates an email. This regex validates 99% of emails in use as of this writing. However, you may use another email regex.
Description
References
How to Find or Validate an Email Address?

regular expression attribute in MVC3

How can I use regular expression attribute in MVC3 on EMAIL field to give an error message if the email entered contains no-email.com?
The exact syntax will depend on the language you are using and possibly the method you are using. These examples should help.
You wouldn't normally need a regular expression to match a simple string.
But, if for some reason, it has to be regex, you would just need to escape the hyphen and dot. Like so:
no\-email\.com
Depending on what you are doing, you may need to match the rest of the email address:
(.*?)no\-email\.com
You may also want to tie "no-email.com" to the end of the string, like so:
(.*?)no\-email\.com$
If you also want to match the # sign to the domain name, do:
(.*?)#no\-email\.com$

Regular Expression for some email rules

I was using a regular expression for email formats which I thought was ok but the customer is complaining that the expression is too strict. So they have come back with the following requirement:
The email must contain an "#" symbol and end with either .xx or .xxx ie.(.nl or .com). They are happy with this to pass validation. I have started the expression to see if the string contains an "#" symbol as below
^(?=.*[#])
this seems to work but how do I add the last requirement (must end with .xx or .xxx)?
A regex simply enforcing your two requirements is:
^.+#.+\.[a-zA-Z]{2,3}$
However, there are email validation libraries for most languages that will generally work better than a regex.
I always use this for emails
^([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}" +
#"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
#".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
Try http://www.ultrapico.com/Expresso.htm as well!
It is not possible to validate every E-Mail Adress with RegEx but for your requirements this simple regex works. It is neither complete nor does it in any way check for errors but it exactly meets the specs:
[^#]+#.+\.\w{2,3}$
Explanation:
[^#]+: Match one or more characters that are not #
#: Match the #
.+: Match one or more of any character
\.: Match a .
\w{2,3}: Match 2 or 3 word-characters (a-zA-Z)
$: End of string
Try this :
([\w-\.]+)#((?:[\w]+\.)+)([a-zA-Z]{2,4})\be(\w*)s\b
A good tool to test our regular expression :
http://gskinner.com/RegExr/
You could use
[#].+\.[a-z0-9]{2,3}$
This should work:
^[^#\r\n\s]+[^.#]#[^.#][^#\r\n\s]+\.(\w){2,}$
I tested it against these invalid emails:
#exampleexample#domaincom.com
example#domaincom
exampledomain.com
exampledomain#.com
exampledomain.#com
example.domain#.#com
e.x+a.1m.5e#em.a.i.l.c.o
some-user#internal-email.company.c
some-user#internal-ema#il.company.co
some-user##internal-email.company.co
#test.com
test#asdaf
test#.com
test.#com.co
And these valid emails:
example#domain.com
e.x+a.1m.5e#em.a.i.l.c.om
some-user#internal-email.company.co
edit
This one appears to validate all of the addresses from that wikipedia page, though it probably allows some invalid emails as well. The parenthesis will split it into everything before and after the #:
^([^\r\n]+)#([^\r\n]+\.?\w{2,})$
niceandsimple#example.com
very.common#example.com
a.little.lengthy.but.fine#dept.example.com
disposable.style.email.with+symbol#example.com
other.email-with-dash#example.com
user#[IPv6:2001:db8:1ff::a0b:dbd0]
"much.more unusual"#example.com
"very.unusual.#.unusual.com"#example.com
"very.(),:;<>[]\".VERY.\"very#\\ \"very\".unusual"#strange.example.com
postbox#com
admin#mailserver1
!#$%&'*+-/=?^_`{}|~#example.org
"()<>[]:,;#\\\"!#$%&'*+-/=?^_`{}| ~.a"#example.org
" "#example.org
üñîçøðé#example.com
üñîçøðé#üñîçøðé.com