Hi
I have textbox with numeric and text data type. I want that user should only enter numeric values or dot in numeric boxes. In text boxes user can enter only alphabets using custom directive.
Thanks
Hi
I have textbox with numeric and text data type. I want that user should only enter numeric values or dot in numeric boxes. In text boxes user can enter only alphabets using custom directive.
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Jun 7, 2024, 4:07 AM
Hello Ramco,
You can follow the below steps to create a custom directive and use in the angular project,
1. Create directive typescript
2. Create custom directory logic
3. use for text input,
4. Add to the module
Naimish MakwanaPosted Jun 7, 2024, 4:48 AM
Sure, you can create custom directives in Angular to restrict the input in textboxes. Here’s how you can do it:
You can use these directives in your HTML like this:
The
numericInputdirective will only allow numeric input and dots, and thealphaInputdirective will only allow alphabetic input. Please replace'@angular/core'with the correct import path in your project. Also, don’t forget to declare these directives in your module.Thanks
Rajendra TaradalePosted Jun 7, 2024, 4:23 AM
You can explore - https://www.c-sharpcorner.com/blogs/angular-reusable-loader-directive
Jayraj ChhayaPosted Jun 6, 2024, 10:15 AM
To achieve this functionality, you can create custom directives in Angular. Below is an example of how you can create directives for numeric and text input validation:
Text DirectiveIn your HTML template, apply the directives accordingly: