regular expression attribute in MVC3 - regex

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$

Related

Flutter email input formatter does not work

I have a Flutter TextFormField for email with input formatter as below.
var emailAddressFormatter = FilteringTextInputFormatter.allow(RegExp(
r"[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+#[a-zA-Z0-9]+\.[a-zA-Z]+"));
The problem is, when trying to input any character in the field it does not allow. The regex looks fine to me. When the formatter is removed the field accepts any character with any format. What am I going wrong?
The issue is that the FilteringTextInputFormatter that you're using rejects anything that does not match your regex. When you enter just a single character, it does not match your regex, so the character is rejected.
I know little about regex so I'm not sure if it's possible, but you would need a regex that would be able to match every string as you type e.g. a, am, amani#, amani#gmail.com.
I would personally not try to do filtering such as this. Instead, I would just allow all valid characters that are valid in email addresses to be present in the email and not enforce the specific format with the # and .. Then I would use a validator to check that the email is valid upon form submission.
If you don't like the alternate solution I proposed above and you can't use regex, you can make your own input formatter quite easily with TextInputFormatter.withFunction.

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!

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.

HTML5 pattern validation being ignored

I have an email input field that I have a regex of ^[^#]+#[^#.]+.[^#]+$, but when ran it is not requiring the .com.
Go to https://jsfiddle.net/uscktx9d/ and type in www#www and hit submit. This should fail validation but is not. As you can see here https://regex101.com/r/pB6iF4/1, the regex should be requiring the .com.
Why is my HTML5 not requiring this?
If you're going to use HTML5 input validation for an email, use type email. This will do native HTML5 validation for emails and have added benefits (like showing an # symbol on mobile devices' virtual keyboards).
Also, remember that any frontend validation should be re-validated in the backend.
To answer your question, though, you need to escape . with a backslash.
In a regex, a literal dot should be declared as an escaped \. symbol. See Special characters in regular expressions that should be escaped if you want to make sure they are treated as literals.
Also, HTML5 pattern attribute value is anchored by default, i.e. the whole pattern is wrapped into ^(?: and )$.
The regular expression language used for this attribute is the same as that used in JavaScript, except that the pattern attribute is matched against the entire value, not just any subset (somewhat as if it implied a ^(?: at the start of the pattern and a )$ at the end).
Thus, you just need to use
<input name="asdf" pattern="[^#]+#[^#.]+\.[^#]+" placeholder="email#example.com" title="email#example.com">
See updated fiddle

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