TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maureen Moore
NA
206
0
Text Input for Positive Integers Only
May 18 2020 1:20 PM
I'm trying to make a number input that is for only positive numbers. I have the following html:
<button class="minus-btn" (click)="minus()" type="button" name="button">
<img src="../assets/images/minus.svg" alt="minus" />
</button>
<input ng-pattern="^(0|\+?[1-9]\d*)$" class="num" name="quantity" [value]="quantity" type="number" min="0">
<button class="plus-btn" (click)="plus()" type="button" name="button">
<img src="../assets/images/plus.svg" alt="plus" /></button>
As you can see, I've implemented ng-pattern and min value but neither one works. In the controller:
quantity: number=1;
i=1;
plus(){
this.i++;
this.quantity=this.i;
}
minus(){
this.i--;
this.quantity=this.i;
}
When I add the following to the controller, I get the error " Property 'match' does not exist on type 'number'"
this.quantity.match(/^(0|\+?[1-9]\d*)$/g);
Reply
Answers (
3
)
How to implement rich textbox control in angular application
Compatible version of file-saver for angular6 + rsjx6.0.0 ?