javascript - Angularjs regex pattern -


i not in regex , here problem need create regex following criteria minimum of 10 characters uppercase letters, lowercase letters, @ least 1 number, @ least 1 special character , not matches username.

and here regex /((?=.*\d)(?=.*[a-z])(?=.*[a-z])(?=.*[0-9])(?=.*[@#$%]).{10,50})/

and below html

<input ng-model="form.account.username" name="accountusername" type="text" ng-focus ng-minlength=3 ng-maxlength=16 placeholder="your account username" ng-blur="makeitdirty(checkout.accountusername)" required ng-ensure-unique ng-pattern="/^[a-za-z0-9_-]{3,16}$/" /> <input ng-model="form.account.password" name="accountpassword" ng-focus type="password" ng-blur="makeitdirty(checkout.accountpassword)" required placeholder="your account password" ng-pattern="/((?=.*\d)(?=.*[a-z])(?=.*[a-z])(?=.*[0-9])(?=.*[@#$%]).{10,50})/" />

the criteria can't catch make password invalid if password matches or contains username.

use right tool job. while regular expressions great first part of problem (enforcing level of password complexity); it's terrible solution second part of problem. don't use regex when simple .indexof() job. know it's nice in single pattern/check, best option separate them 2 checks. 1 runs through regex enforce password rules while second check ensures username not substring of password.


Comments