I have a field password
and a pattern, but it only validates some passwords for me.
Pattern policy:
- Minimum 8 characters
- An uppercase letter
- a lowercase letter
- A special character (
!#$%&/()?¡_-
)
I use the Ionic 2 framework .
I am doing the validation like this:
public passRegex ="(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$" return this.formBuilder.group({
correo: ['',Validators.compose([Validators.required,Validators.pattern(this.emailRegex)])],
confirmarEmail: ['',Validators.compose([Validators.required,Validators.pattern(this.emailRegex)])],
passwordRetry: this.formBuilder.group({
clave: ['', [Validators.pattern(this.passRegex)]],
passwordConfirmation: ['', [Validators.pattern(this.passRegex)]]
},{validator:this.compararPass('clave','passwordConfirmation')})
},{validator:this.compararEmail('correo','confirmarEmail')});
If I put the chain it Ejemploj#240518
works, but if I put Pruebaenki#123456
it it doesn't work.
ionic info:
Your system information:Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.2
Ionic CLI Version: 2.1.8
Ionic App Lib Version: 2.1.4
Ionic App Scripts Version: 0.0.43
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.8
Node Version: v6.5.0
Xcode version: Not installed
The following regular expression matches a string of at least 8 characters, with 1 lowercase letter, 1 uppercase letter, and a symbol between
!#$%&/()?¡_-
. It does not consider letters with accents,ñ
or other diacritics such as lowercase or uppercase.Regex:
Description:
Remember that with a PatternValidator the regular expression will be compared against the entire string, so it is already anchored to
^
(the beginning) and$
(the end of the text).(?=.*[-!#$%&/()?¡_])
- It is a positive assertion ( positive lookahead ) that matches the following expression without consuming characters (and then returns to the position it was in before trying):.*
- 0 or more characters[-!#$%&/()?¡_]
- It is a character class ( character class ) that matches 1 character (1 symbol between the brackets).(?=.*[A-Z])
- Positive assertion that matches any character and then 1 uppercase. Remember that, since no character was consumed so far, we continue trying from the beginning of the text.(?=.*[a-z])
- Positive assertion that matches any character and then a lowercase 1. Remember that, since no character was consumed so far, we continue trying from the beginning of the text..{8,}
- The dot matches any character (except\n
). With{8,}
we are repeating the previous structure between 8 or more times. That is, it matches 8 or more characters (any), to check the minimum length.demonstration:
https://regex101.com/r/VUXm3b/2