Tony
Tony

Reputation: 57

How to handle invalid decimal value in Angular 4 typescript?

enter image description here

The problem is if I not give any digit after '.' then it shows error

I need output like the following

23 -> OK

5 -> OK

3.5 -> OK

  1. -> Not OK

The UI Code is look like this enter image description here

Upvotes: 1

Views: 306

Answers (2)

riorudo
riorudo

Reputation: 1227

You have to change your regex pattern. Try to replace the last part (\.\d{1,2})? with (\.)?(\d{1,2})?. This means that the . can be set without having to enter the other two digits. You can play around with your regex pattern on regex101.com.

Upvotes: 1

Papun Sahoo
Papun Sahoo

Reputation: 428

You can use below code into your Angular 4

    <input class="k-textbox" format="{0:c2}"  type="number" step="0.01" onkeydown="return event.keyCode !== 69">

Upvotes: 0

Related Questions