I want to validate a string using in bootstrapvalidator. String must contain
Minimum of 6 characters.
maximum 12 characters
Must contains atleast one numeral.
Must contain atleast one capital letter.
Must contain atleast one special characters
How can I do that? Can anyone show me the regular expression to do that?
I am already have this:
regexp:
{
regexp: "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$#$!%*?&])[A-Za-z\d$#$!%*?&]{6,12}",
message: 'The password should contain Minimum 6 and Maximum 12 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character:'
}
But if i enter correct password requirements also it is showing redcolor and it is not changing to green color
/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[$#!%?&]).{6,12}$/
Please check this thread for more information! Try to search the website for a solution before posting a question.
Related
i have been thinking about this a lot.
So i wanna create a table which contains a password.
The password should at least be 6 chars long a contain minimum 2 numbers.
My version was:
create table User (
passwort varchar(80) not null check (length(passwort) >= 6 and passwort like '%[0-9]%[0-9]%')
);
The Problem with this approach is that the password has to contain [0-9] twice instead of the actual numbers. Does anyone know how to get rid of that problem ?
Thanks in advance.
How about .*?\d.*?\d.*?
This ensures that between zero or more characters (including digits), there must be 2 digits.
While I still recommend you split the work in 2 as per my comment, ie.
Check the length of the string.
Use the actual expression to check if the string contains 2 numbers.
You can use the following expression: ^(?=.{6,}).*?\d.*?\d.*?$. What is does is that it looks ahead for a minimum of 6 characters and then checks that the string is made up from 2 numbers, which can be separated by 0 or more characters.
An example of the expression is available here.
I need to find out specific user names that meet a certain - albeit rather wide - criteria. My knowledge at regex is very limited so while my regex constructs did match what I wanted, they also matched about everything else. Can you help me?
The requirements for a valid match are:
string length: exactly 7 characters
contains only alphanumeric characters, mixed upper and lower case, or numbers 0-9
contains at least one number 0-9, can be more than that but never 3 in a row
not all upper case (can be all lower case but never upper case)
Unfortunately, the numbers can be anywhere in the string, and the alphanumeric characters can also be any combination.
Here is an excerpt of the data I need to match:
cgxh21o *
crittaz
Mist246
nOnameR
Gorebag
pu50pce *
rmygy62 *
aeifnz0 *
orp5k1v *
okn5nvr *
The ones marked with * are the ones I want to match. The remaining ones are valid and must not be included.
Is this even possible using regex?
My last attempt was:
/[a-z{0,}A-Z{0,}0-9{1,}]{7}+
but then I found user names that didn't follow that notation at all (more than one number) so it didn't work.
Here's a relatively short and simple regex that will work:
(?=(^.{7}$))(?=.*[a-z])(?=.*\d)(?!.*\d{3})
regex101 demo
Explanation:
(?=(^.{7}$)) check that there's exactly 7 characters (and capture them)
(?=.*[a-z]) at least one lower case letter
(?=.*\d) at least one digit
(?!.*\d{3}) there isn't 3 digits in a row anywhere
Here's a Python demo:
import re
pattern = re.compile(r"(?=(^.{7}$))(?=.*[a-z])(?=.*\d)(?!.*\d{3})")
ls = ["cgxh21o", "crittaz", "Mist246", "nOnameR", "Gorebag",
"pu50pce", "rmygy62", "aeifnz0", "orp5k1v", "okn5nvr",
"OKN5NVR", "short1", "aeifnz0aaaaaa", "12CeE12"]
for elem in ls:
print(elem, bool(re.search(pattern, elem)))
Output:
cgxh21o True
crittaz False
Mist246 False
nOnameR False
Gorebag False
pu50pce True
rmygy62 True
aeifnz0 True
orp5k1v True
okn5nvr True
OKN5NVR False
short1 False
aeifnz0aaaaaa False
12CeE12 True
You could use lookahead assertions:
^(?=[^a-z\s]*[a-z])(?=[^\d\s]*\d)(?!.*\d{3})[a-zA-Z0-9]{7}$
Explanation
^ Start of string
(?=[^a-z\s]*[a-z]) Assert a lowercase char a-z
(?=[^\d\s]*\d) Assert a digit
(?!.*\d{3}) Assert not 3 digits in a row
[a-zA-Z0-9]{7} Match 7 times any of the listed
$ End of string
Regex demo
Here's a possibility based on your updated question:
^(?![a-zA-Z]{7}|.*[0-9]{3}.*|[A-Z0-9]{7})([a-zA-Z0-9]){7}$
Doesn't match
crittaz
nOnameR
Gorebag
ABCDEFG
aBCDEFG
1234567
Mist246
ABCDEF7
Matches
cgxh21o
pu50pce
rmygy62
aeifnz0
orp5k1v
okn5nvr
There's probably a number of ways to do this. This one looks for 7 alphanumeric, but not if there's only 7 alphabetic, not if there's only uppercase and numbers, and not if there's 3 digits in a row...
Im looking for a regex that checks for:
a minimum of 2 numbers and
a minimum of 1 capital letter and
a minimum of 4 lowercase letters
And also checks for:
a maximum of 30 characters
I've been trying to make this but all my creations don't work :)
You can leave the maximum out too if you can't do it, I could check it in another way.
I guess the order of those conditions is arbitrary. Therefore there is no need to do it using just 1 regexp. For each condition, you can have 1 regexp and then you can do a logical conjunction in your favorite language and it would be much more readable than one super-cool-ninja-regexp.
a minimum of 2 numbers
".*\d.*\d.*"
a minimum of 1 capital letter and
".*[A-Z].*"
a minimum of 4 lowercase letters
".*[a-z].*[a-z].*[a-z].*[a-z]"
a maximum of 30 characters
".{6,30}"
^(?=.*\d.*\d)(?=.*[A-Z])(?=.*[a-z].*[a-z].*[a-z].*[a-z]).{7,30}$
But if you want only the alphanumerics, then:
^(?=.*\d.*\d)(?=.*[A-Z])(?=.*[a-z].*[a-z].*[a-z].*[a-z])[a-zA-Z0-9]{7,30}$
(?=.*\d.*\d): at least two digits
(?=.*[A-Z]): one caps letter
(?=.*[a-z].*[a-z].*[a-z].*[a-z]): minimum four lowercase
[a-zA-Z0-9]{7,30}: length between 7-30
I just need a Regular Expression that will validate a phone no entered in the textbox. That textbox can allow only numbers,dashes(-) and plus(+) and should be maximum of 15 characters and minimum of 11 characters.
(+) can(Optional) only come at starting of phone no.
Please answer.
Your question is answered by this:
\+?[\d-]{1,13}
\+? means "zero of one '+' character"
[\d-]{1,13} means "from 1 to 13 digits or hyphen"
However, I think you should use something a little more prescriptive. Perhaps requiring there's at least say 8 digits and the hyphen can't be first or last:
^(?=(.*\d){8,13})\+?(?!-)[\d-]*(?<!-)$
Disregarding your 13 character constraint, you can use this regex:
^((\+[0-9]([0-9]{2}|[1-9])?-)?([1-9][0-9]{2}-)?[1-9][0-9]{2}-[0-9]{4})?$
I'm looking for a custom RegEx expression (that works!) to will validate common phone number with area code entries (no country code) such as:
111-111-1111
(111) 111-1111
(111)111-1111
111 111 1111
111.111.1111
1111111111
And combinations of these / anything else I may have forgotton.
Also, is it possible to have the RegEx expression itself reformat the entry? So take the 1111111111 and put it in 111-111-1111 format. The regex will most likely be entered in a Joomla / some type of CMS module, so I can't really add code to it aside from the expression itself.
\(?(\d{3})\)?[ .-]?(\d{3})[ .-]?(\d{4})
will match all your examples; after a match, backreference 1 will contain the area code, backreference 2 and 3 will contain the phone number.
I hope you don't need to handle international phone numbers, too.
If the phone number is in a string by itself, you could also use
^\s*\(?(\d{3})\)?[ .-]?(\d{3})[ .-]?(\d{4})\s*$
allowing for leading/trailing whitespace and nothing else.
Why not just remove spaces, parenthesis, dashes, and periods, then check that it is a number of 10 digits?
Depending on the language in question, you might be better off using a replace-like statement to replace non-numeric characters: ()-/. with nothing, and then just check if what is left is a 10-digit number.