I would like to prohibit . in front of the # in email validation in javascript.
What I have:
^([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})(\]?)$
So email.#domain.com is prohibited, but email.email#domain.com should be accepted.
What could I do?
Here is slightly modified version of your regex. Basically, ^([a-zA-Z0-9_\-\.]+) was changed to ^([a-zA-Z0-9_\-]+)(\.[a-zA-Z0-9_\-]+)*:
^([a-zA-Z0-9_\-]+)(\.[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})(\]?)$
Related
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
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
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.
Given the following Facebook profile and page URLs, my intent is to extract profile ids or usernames into the first match position.
http://www.facebook.com/profile.php?id=123456789
http://www.facebook.com/someusername
www.facebook.com/pages/Regular-Expressions/207279373093
The regex I have so far looks like this:
(?:http:\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(\d.*))?([\w\-]*)?
Which produces the following results:
Result 1:
123456789
Result 2:
someusername
Result 3:
207279373093
The ideal outcome would look like:
Result 1:
123456789
Result 2:
someusername
Result 3:
207279373093
That is to say, I'd like to have the profile identifier to always be returned in the first position.
It would also be ideal of www.facebook.com/ and facebook.com/ didn't match either.
I'd recommend Rad Software Regular Expression Designer.
Also this online tool is great https://regex101.com/ ( though most people prefer http://regexr.com/ )
(?:(?:http|https):\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\-]*)?
I made a gist a while back that works fine against the given examples:
# Matches patterns such as:
# http://www.facebook.com/my_page_id => my_page_id
# http://www.facebook.com/#!/my_page_id => my_page_id
# http://www.facebook.com/pages/Paris-France/Vanity-Url/123456?v=app_555 => 45678
# http://www.facebook.com/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/#!/page_with_1_number => page_with_1_number
# http://www.facebook.com/bounce_page#!/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/bounce_page#!/my_page_id?v=app_166292090072334 => my_page_id
/(?:http:\/\/)?(?:www\.)?facebook\.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*([\w\-]*)/
To get the latest version: https://gist.github.com/733592
Only this regular expression works correctly for all FB URLs:
/(?:https?:\/\/)?(?:www\.)?(?:facebook|fb|m\.facebook)\.(?:com|me)\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*([\w\-\.]+)(?:\/)?/i
I've tried every single answer above and each one doesn't work for at least one reason. This most likely won't be helpful to OP, but if anybody like me finds this in a web search, I believe this is the correct answer:
^(?:.*)\/(?:pages\/[A-Za-z0-9-]+\/)?(?:profile\.php\?id=)?([A-Za-z0-9.]+)
Supports basically everything I can think of, except verifying that the domain contains facebook.com. If you need to check if the URL is valid, this should be done outside of a regular expression to make sure the page or profile actually exists. Why check it twice, especially when one of the checks is incomplete?
Doesn't cut off the first character
Grabs URLs with periods
Ignores superfluous GET parameters
Supports /usernames as provided by the Facebook app
Supports both profile URL structures
Doesn't match facebook.com/ or facebook.com (by ignoring them)
Works with and without www. (by ignoring it)
Supports both http and https (by ignoring them)
Supports both facebook.com and fb.com (by ignoring them)
Supports pages with special characters in the name (by ignoring them)
Supports #! (by ignoring it)
Supports bounce_page#! (by ignoring it)
The most completed pattern for Facebook profile url:
/(?:https?:\/\/)?(?:www\.)?facebook\.com\/.(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*([\w\-\.]*)/
It detects all the cases + one important difference. Other regex patterns recognize http://www.facebook.com/ as a valid Facebook Profile URL while it is not a valid Profile url. It is just the original Facebook URL and not a user or page address. But this regex can distinguish a normal url from a profile and page url and only accepts the valid one.
Matches facebook.com, m.facebook.com, mbasic.facebook.com and fb.me (short link)
/(?:https?:\/\/)?(?:www\.)?(mbasic.facebook|m\.facebook|facebook|fb)\.(com|me)\/(?:(?:\w\.)*#!\/)?(?:pages\/)?(?:[\w\-\.]*\/)*([\w\-\.]*)/ig
Facebook URL regex DEMO
Regex that will correctly identify profile pages with a . in the name like www.facebook.com/my.name and it will also exclude www.facebook.com/ or home.php as it is not a valid facebook page.
https://regex101.com/r/koN8C2/2
(?:(?:http|https):\/\/)?(?:www.|m.)?facebook.com\/(?!home.php)(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\.-]+)
Let me know if you found any that are not matched.
This works well for me. It can detect personal profile url, and exclude all the fan pages, and groups.
.+www.facebook.com\/[^\/]+$
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])?