admin管理员组文章数量:1025207
Can any one suggest me how can I add ng-pattern / directive / RegEx globally ? so that I do not want to go to each page and touch every input by adding ng-pattern or adding directive.
My application has around 200 pages , I don't want to restrict each text input with only alpha numeric.
is there any solution write mon logic that will apply for whole application ? Please suggest, I am using Angular 8.
Thank you In advance.
Can any one suggest me how can I add ng-pattern / directive / RegEx globally ? so that I do not want to go to each page and touch every input by adding ng-pattern or adding directive.
My application has around 200 pages , I don't want to restrict each text input with only alpha numeric.
is there any solution write mon logic that will apply for whole application ? Please suggest, I am using Angular 8.
Thank you In advance.
Share Improve this question asked Oct 1, 2020 at 21:49 Praveen BomminaniPraveen Bomminani 432 silver badges9 bronze badges 3- You could apply it to all inputs using a directive but I don't know if you really want to do that. You might be better served by writing your own input ponent or your own form control factory – Aluan Haddad Commented Oct 1, 2020 at 23:35
- 1 Thank you Aluan, if I create directive .. I need to import that directive in all ponents. basically I don't want to touch any input or ponent.. is there a way I can do by importing that directive in app-module ? the it will effect in all ponents. Please suggest. – Praveen Bomminani Commented Oct 2, 2020 at 12:25
- 1 I got it, I need to define in root module, as suggested in stackblitz./edit/…. – Praveen Bomminani Commented Oct 2, 2020 at 12:37
1 Answer
Reset to default 4if you make a directive with selector input
is applied to all yours inputs
@Directive({
selector: 'input'
})
You can use a directive like this SO you are next to get it, only replace the input set mask for something like
@Input()
set mask(value) {
if (value == "*")
this.notApplied = true;
else
this.regExpr = new RegExp(value);
}
declare regExpr as
private regExpr = new RegExp(/^[A-Z|a-z|0-9]+$/);
and change the host listener checkin if this.notApplied
@HostListener('input', ['$event'])
change($event) {
if (this.notApplied)
return;
...
}
All your inputs that has no [mask]="what ever"
applied the mask by defect
A input with mask="*"
will be a "normal" input
See the forked directive
Can any one suggest me how can I add ng-pattern / directive / RegEx globally ? so that I do not want to go to each page and touch every input by adding ng-pattern or adding directive.
My application has around 200 pages , I don't want to restrict each text input with only alpha numeric.
is there any solution write mon logic that will apply for whole application ? Please suggest, I am using Angular 8.
Thank you In advance.
Can any one suggest me how can I add ng-pattern / directive / RegEx globally ? so that I do not want to go to each page and touch every input by adding ng-pattern or adding directive.
My application has around 200 pages , I don't want to restrict each text input with only alpha numeric.
is there any solution write mon logic that will apply for whole application ? Please suggest, I am using Angular 8.
Thank you In advance.
Share Improve this question asked Oct 1, 2020 at 21:49 Praveen BomminaniPraveen Bomminani 432 silver badges9 bronze badges 3- You could apply it to all inputs using a directive but I don't know if you really want to do that. You might be better served by writing your own input ponent or your own form control factory – Aluan Haddad Commented Oct 1, 2020 at 23:35
- 1 Thank you Aluan, if I create directive .. I need to import that directive in all ponents. basically I don't want to touch any input or ponent.. is there a way I can do by importing that directive in app-module ? the it will effect in all ponents. Please suggest. – Praveen Bomminani Commented Oct 2, 2020 at 12:25
- 1 I got it, I need to define in root module, as suggested in stackblitz./edit/…. – Praveen Bomminani Commented Oct 2, 2020 at 12:37
1 Answer
Reset to default 4if you make a directive with selector input
is applied to all yours inputs
@Directive({
selector: 'input'
})
You can use a directive like this SO you are next to get it, only replace the input set mask for something like
@Input()
set mask(value) {
if (value == "*")
this.notApplied = true;
else
this.regExpr = new RegExp(value);
}
declare regExpr as
private regExpr = new RegExp(/^[A-Z|a-z|0-9]+$/);
and change the host listener checkin if this.notApplied
@HostListener('input', ['$event'])
change($event) {
if (this.notApplied)
return;
...
}
All your inputs that has no [mask]="what ever"
applied the mask by defect
A input with mask="*"
will be a "normal" input
See the forked directive
本文标签: javascriptI want to restrict input type text only Alphanumeric in Angular 9 globallyStack Overflow
版权声明:本文标题:javascript - I want to restrict input type text only Alphanumeric in Angular 9 globally - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745613543a2159149.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论