问题
I have a password field that i will like to ensure that the users input a password that will meet the criteria stated below:-
- Must contain at least one capital letter
- Must contain at least one small letter
- Must contain a number and lastly
- A special character like #%@!*(()+= ( optional )
I have tried to use the data-parsley-pattern, and data-parsley-type but not getting the required results.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.6.0/parsley.js"></script>
<form data-parsley-validate>
<input type="password" name="password" id="password" minlength="6" data-parsley-type="alphanum" data-parsley-pattern="^/^[a-zA-Z0-9\-\_]$/" class="form-control allForms" required data-parsley-required-message="Your password" data-parsley-trigger="change focusin" placeholder="Enter password">
</form>
回答1:
I think that for efficiency and maintainability you should either define a custom validator like explained here or a regex one if you're good at it (((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?(?=.*[#%@!*(()+=]))).{6,16}
could do the job?);)
回答2:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.6.0/parsley.js"></script>
<form data-parsley-validate>
<input type="password" name="password" id="password" minlength="6" data-parsley-type="alphanum" data-parsley-pattern="^/^[a-zA-Z0-9\-\_]$/" class="form-control allForms" required data-parsley-required-message="Your password" data-parsley-trigger="change focusin" placeholder="Enter password">
</form>
来源:https://stackoverflow.com/questions/40453419/enforce-strong-password-policy-with-parsley-js