regex - angular ng-pattern match any non-word, non-space, non-digit not working? -


<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script>    <div ng-app>      <form class="edit-segment edit-form" name="form">          <input type="text" class="form-control" ng-model="dname" name="name" maxlength="100" ng-pattern="/[a-z0-9 ]+/" ng-required='true' />          <output>{{form}}</output>          <output>{{dname}}</output>          <output>{{form.name.$valid}}</output>      </form>  </div>

the pattern is:
/[a-z0-9 ]+/

for reason angular-infused html not acting way i'm expecting. i'm expecting happen user enters non-word, non-digit, non-space character, input becomes invalid, $form.name.$valid should false.

instead happens is, long input contains letter, number or space, input becomes $valid becomes true.
so:
lkajskdjf<.?{}
valid

.,.,..,{}{][].,
not valid.

.,.,..,{}{][].,\
valid.

?>?./..,./9k
valid.

kjkljd lkjsdf 90
valid.

the 1 should valid last one... understanding of ng-pattern, evidently wrong, input valid long characters entered match regex in ng-pattern.

what's going on here?
why behavior i'm expecting not behavior i'm getting?

the pattern should /^[a-z0-9 ]+$/, ^ , $ symbols mean "begins with" , "ends with" respectively. mean regex match , character class.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -