Input validation with pattern Angular 2

前端 未结 2 1901
Happy的楠姐
Happy的楠姐 2021-02-15 14:07

I\'m currently writing a simple form in ionic 2 (Angular 2). I was wondering how I\'d add a simple regular expression pattern to the validation:

I basically have this:

2条回答
  •  盖世英雄少女心
    2021-02-15 14:28

    Add the pattern to a variable

    var pattern=/06([0-9]{8})/;
    

    and bind the attribute to it

     
    

    Seems this PR https://github.com/angular/angular/pull/6623/files needs to land first.

    There is still an open issue https://github.com/angular/angular/issues/7595 This prevents pattern being bound to. The pattern needs to be statically added to the DOM (without binding) to work.

提交回复
热议问题