Regex for Active Directory Password policies - javascript

I need a Regex for Active Directory Password policy with the following conditions.
My requirements are:
at least one digit (0-9)
at least one lowercase character
at least one uppercase character
must contain at least one special character and
the length should be minimum 8 characters and maximum of 25

try this. its included with space bar validation.
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\W]).{8,25})

Related

Alter Regex to validate email Domain on RFC 5322 from Java to Oracle sql

I need to alter the below Regex to validate emails domains in a oracle database, according to RFC 5322,
and ensuring that the criteria below are respected as well.
Domain rules that must be respected:
must start an end with a letter or digit and be between 1 and 63 characters long.
may contain uppercase and lowercase Latin letters (A to Z and a to z).
may contain digits 0 to 9, provided that top-level domain names are not all-numeric.
may contain hyphen -, provided that it is not the first or last character, and not consecutive also.
must have at least 2 or more characters (abc#t.com is not valid, but abc#tt.com is valid).
I found on the internet the regex below, that works very well and ensure the rules posted above, in Javascript.
My problem is that ORACLE does not support look-ahead/-behind.
#(?:(?=[A-Z0-9-]{1,63}\.)[A-Z0-9]+(?:-[A-Z0-9]+)*\.){1,8}[A-Z]{2,63}$
So, can anyone please help me on making the necessary modifications in order to work in Oracle sql?

Regex for password with specific restrictions [duplicate]

This question already has answers here:
Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
(42 answers)
Regular expression to check if password is "8 characters including 1 uppercase letter, 1 special character, alphanumeric characters"
(14 answers)
Closed 3 years ago.
I'm trying to come up with a regex that validates passwords. The restrictions are as follows:
Must be at least two of the following:
one lowercase [a-z],
one uppercase [A-Z],
one digit [\d],
one special character [!##\$%\^\&*)(+=._-].
must not begin or end with white-space but can contain white-spaces inside,
must be between 7 and 20 characters long.
So far, this is the last version of what I've come up with:
^(?=.{7,20}$)(?:(?=.*[\d!##\$%\^\&*\)\(+=._-])(?=.*[a-z])\S*|(?=.*[A-Z])(?=.*[\d!##\$%\^\&*\)\(+=._-])\S*|(?=.*[A-Z])(?=.*[a-z])\S*|(?=.*[\d)\(+=._-])(?=.*[!##\$%\^\&*\)\(+=._-])\S*)$
This works for all of the above except letting white-spaces inside. I've gone through multiple regex and this is the best one so far (but also the ugliest).
Edit: Thank you for the fast replies. Why these requirements are in place is beside the point. I know passwords would be more secure if all of the above were required. But as not all customers use password managers...
Now, why is this not a duplicate question? Because no other thread requires any two of the above. They simply start with requiring specific two, than adding another one and so on. This needs to be any two conditions.
Hey you can use below regex to fulfill your requirement
^(?=.\d)(?=.[A-Z])(?=.[a-z])(?=.[^\w\d\s:])([^\s]){7,20}$

JavaScript Regex - custom characters and numbers

I am building a RegEx that is almost complete, but I can not get it to check for digits (0 - 9):
So for example: Jones-Parry is valid but Jones-Parry1 is not. The regex at present looks like this:
^([\\w\\s,'\\-ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüŸçÇŒœßØøÅåÆæÞþÐð]){0,80}$
I have tried using \d and [0-9] but to no avail. All else is working with the regex aside from the numbers. It validates special characters etc.
Any pointers greatly appreciated!
The problem is \w expands to A-Za-z0-9_, which includes digits 0-9. This explains why strings with digit pass your test.
You may want to specify A-Za-z_ directly instead of \w in your regex. It will fix your problem.
As georg has pointed out in the comment, your regex is very weak, since aside from the length requirement, it only checks whether it does not contain any character outside your allowed character set. A string with only spaces, or a string with only punctuation would pass the test.
Anyway, I doubt validating name is a good idea in general. Many assumptions programmers make about name are wrong. Depending on your requirement, you can give user a field for display name, where user can type anything in, and another field for username, where you only allow a strict set of characters.

Email Regular Expression - Excluded Specified Set

I have been researching a regular expression for the better part of about six hours today. For the life of me, I can not figure it out. I have tried what feels like about a hundred different approaches to no avail. Any help is greatly appreciated!
The basic rules:
1 - Exclude these characters in the address portion (before the # symbol): "()<>#,;:\[]*&^%$#!{}/"
2 - The address can contain a ".", but not two in a row.
I have an elegant solution to the rule number one, however, rule number two is killing me! Here is what I have so far. (I'm only including the portion up to the # sign to keep it simple). Also, it is important to note that this regular expression is being used in JavaScript, so no conditional IF is allowed.
/^[^()<>#,;:\\[\]*&^%$#!{}//]+$/
First of all, I would suggest you always choose what characters you want to allow instead of the opposite, you never know what dangerous characters you might miss.
Secondly, this is the regular expression I always use for validating emails and it works perfectly. Hope it helps you out.
/^[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,6}$/i
Rule number 2
/^(?:\.?[^.])+\.?$/
which means any number of sequences of (an optional dot followed by a mandatory non dot) with an optional dot at the end.
Consider four two character sequences
xx matches as two non dot characters.
.x matches as an optional dot followed by a non-dot.
x. matches as a non-dot followed by an optional dot at the end.
.. does not match because there is no non-dot after the first dot.
One thing to remember about email addresses is that dots can appear in tricky places
"..#"#.example.com
is a valid email address.
The "..#" is a perfectly valid quoted local-part production, and .example.com is just a way of saying example.com but resolved against the root DNS instead of using a host search path. example.com might resolve to example.com.myintranet.com if myintranet.com is on the host search path but .example.com always resolves to the absolute host example.com.
First of all, to your specifications:
^(?![\s\S]*\.\.)[^()<>#,;:\\[\]*&^%$#!{}/]#.*$
It's just your regex with (?!.*\.\.) tacked onto the front. That's a negative lookahead, which doesn't match if there are any two consecutive periods anywhere in the string.
Properly matching email addresses is quite a bit harder, however.

Regex to match multiple patterns in any order

I'm validating a password for complexity in an ASP.NET MVC3 app. My current requirements are that it must contain at least one upper case letter, one lower case letter, one digit and no more than three repeated characters. I'd like to generalise those numbers though, and also add a condition for non-alphanumeric characters.
At present, I'm validating server-side only, so I'm able to call Regex.IsMatch multiple times using one regex for each condition. I want to be able to validate client-side too though. because unobtrusive jQuery validation will only allow one regex, I need to combine all five conditions into a single pattern.
I don't know much when it comes to regular expressions but I've been doing a bit of reading recently. I may be missing something simple but I can't find a way to AND multiple patterns together the way a | will OR them.
You can do this (in .NET) with several lookahead assertions in a single regex:
^(?=.*\p{Lu})(?:.*\p{Ll})(?=.*\d)(?=.*\W)(?!.*(.).*\1.*\1)
will match if all conditions are true.
^ # Match the start of the string
(?=.*\p{Lu}) # True if there is at least one uppercase letter ahead
(?=.*\p{Ll}) # True if there is at least one lowercase letter ahead
(?=.*\d) # True if there is at least one digit ahead
(?=.*\W) # True if there is at least one non-alnum character ahead
(?!.*(.).*\1.*\1) # True if there is no character repeated twice ahead
Note that the match is not going to consume any characters of the string - if you want the match operation to return the string you're matching against, add .* at the end of the regex.
In JavaScript, you can't use Unicode character properties. So instead you could use
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_])(?!.*(.).*\1.*\1)
which will of course only use ASCII letters for validation. If that's OK for you, fine. You could go and augment the character classes like [A-ZÄÖÜÀÈÌÒÙÁÉÍÓÚ] etc. etc. but you would probably never be complete with this. On the server side, if you want the validation to yield the same result, you'd have to specify RegexOptions.ECMAScript so the .NET regex engine behaves like the JavaScript engine (thanks Alan Moore for noticing!).

Categories

Resources