javascript - Js regex for password validation match -
i using following regex in conjunction abide foundation validating password:
<form id="setpassword" action="{{ url('changepasswordwithouttoken') }}" method="post" class="account setpassword" data-abide="ajax" novalidate="novalidate"> {{ csrftoken() }} <input type="hidden" name="token" value="{{ data.token }}"/> <div class="row"> <div class="large-12 columns"><p>{{ 'pleasechooseapassword'|trans }}</p></div> <div class="large-12 columns"> <label class="password" for="setpasswordfield"> <input type="password" id="setpasswordfield" name="setpasswordfield" pattern="passwordadditional" required placeholder="{{ 'accountloginlabelpassword'|trans }}" /> <small class="error">{{ 'passwordshouldcontain'|trans }}</small> </label> </div> </div> <div class="row"> <div class="large-12 columns"> <label class="confirmpassword" for="confirmsetpassword"> <input type="password" id="confirmsetpassword" name="confirmsetpassword" data-equalto="setpasswordfield" required placeholder="{{ 'confirmpassword'|trans }}" /> <small class="error">{{ 'accountregistrationerrordifferentpasswords'|trans }}</small> </label> </div> </div> <div class="row"> <div class="small-12 medium-5 large-4 columns"> <button type="submit" class="button" id="setpasswordbtn">{{ 'savechanges'|trans }}</button> </div> </div>
js:
patterns: { passwordadditional: /^(?=.[a-z])(?=.[a-z])(?=.\d)(?=.[_\w\s]).{8,}/ }
it deosn't seem pick symbol, when enter new password without symbol validation message disappears. shouldn't haven't inserted symbol inside new password. regex wrong?
your regex wrong, there 2 mistakes made:
(?=.[a-z])
looking ahead single character followed lowercase letter, intention find lowercase letter in string, .
should modified *
(0 or more times)
(?=.[_\w\s])
looking ahead single character followed either underscore or non-word or non-space, litereally everything. seems check symbol, match (if there @ least 2 characters). use negation achieve this, (?=.*[^a-za-z0-9\s])
this leads following regex
/^(?=.*[a-z])(?=.*[a-z])(?=.*\d)(?=.*[^a-za-z0-9\s]).{8,}$/
you can @ https://regex101.com/r/dg9xl8/1 demo.
Comments
Post a Comment