It’s been a long time, but here’s a chance to validate only with a pure regex:
/(?!\s)(?=.*?[a-z]{1,})(?=.*?[A-Z]{1,})(?=.*?\d{1,}).*(?=.?[^a-zA-Z0-9]{1,})?.([^\s]){8,}/g
In the last parentheses, inside the square bracket, you can delete all the characters you want, for example, if you want to remove quotes:
([^\s'"`])
Testing:
Explaining a little:
When you want more than one rule in regex, where you need to go through them all, you use (?=seu_regex)
(would be similar to &&
in programming languages).
As in this case, no matter the order of what was typed, as long as it has all the characters, so for each desired rule, you use: .*?
, something like "regardless of how many or what comes before, validate my rule". Soon:
(?=.*?seu_regex)
When you need to quantify your rules, just use {n}
for an exact amount, or {n,} for "from". So, if you wanted to force at least four lower-case letters, {4,}
. Following the case of your question:
(?=.*?seu_regex{1,})
It can be based on this: https://answall.com/q/337924/112052
– hkotsubo
If the encoding for UTF8 might be better to use
mb_strlen()
otherwise an accented character can count as more than 1 byte.– fernandosavio
@hkotsubo Thank you so much for the base, will help me mto yes, just give an implemented!
– Wees Smith
@fernandosavio Thank you so much for remembering this detail that tbm went unnoticed! Vcs are too much!
– Wees Smith
so I leave 100% I will post here the answer
– Wees Smith
Ah, and "special characters" is a "vague" definition, since each one defines a way (which is the exact list of special characters? It depends, each one implements a way) So you must define which will accept and which will not, gives a read here also: https://en.stackoverflow.com/a/342737/112052
– hkotsubo
correct Horse Battery Staple
– Jefferson Quesado