2017-04-15 3 views
0

ich diesen Fehler, wenn ich das ng-Muster bin setzen. Warum das?

<input type="password" required ng-pattern="/^(?=.*[A-Za-z])(?=.*\d)(?=.*[[email protected]$!%*#?&])[A-Za-z\[email protected]$!%*#?&]{8,}$/" 

und wie ein setzen Fehlermeldung, wenn es nicht gültiges Muster, ist dies der richtige

<span style="color:red" ng-show="f1.Password.$error.pattern"> 
    Invalid Pattern 
</span> 

Antwort

1

Sie einfache Möglichkeit, Ihr Passwort verwenden können, hier zu validieren:

HTML:

Hier
<form name="myForm" style="padding-top:30px; margin-left:30px"> 
    <label for="password">Password</label> 
    <input type="password" id="password" name="password" ng-model="formData.password" ng-minlength="8" ng-maxlength="20" ng-pattern="/(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])/" required /> 
    <span ng-show="myForm.password.$error.required && myForm.password.$dirty">required</span> 
    <span ng-show="!myForm.password.$error.required && (myForm.password.$error.minlength || myForm.password.$error.maxlength) && myForm.password.$dirty">Passwords must be between 8 and 20 characters.</span> 
    <span ng-show="!myForm.password.$error.required && !myForm.password.$error.minlength && !myForm.password.$error.maxlength && myForm.password.$error.pattern && myForm.password.$dirty">Must contain one lower &amp; uppercase letter, and one non-alpha character (a number or a symbol.)</span> 
    </br></br> 
    <button type="submit" class="btn" ng-disabled="!myForm.$valid">Submit</button> 
    </form> 

ist der Arbeits Plunk: http://plnkr.co/edit/f09GAGbSKAof3ORm8g5x

+0

Vielen Dank – Woshooo