Angular - Apply decimal pipe to an input - javascript

I want to apply decimal pipe on an input so the user can see comma separated numbers as he/she types. I have tried the ngx-mask but that only works if you type in the input. When you patch a value to the input it doesn't transform the value into decimal format.

Basically you can use ngModelChange when you value change you can use a pipe in your ngModel as below
<input [ngModel]="item.value | currency" (ngModelChange)="item.value=$event"
name="name" type="text" />
and more detail about it check this

Related

Preventing users to enter negative sign '-' in angular input field

is there a way to stop users from entering - sign in angular inputs?
Or clear the sign as soon as they entered it?
I don't want values like -1, 9-, 124-5433.
If you only want to accept numeric vaues you can add a min attribute to the html input, like
<input type="number" min="0">
So this won't let you insert negative values.
You can try below way in your input field using oninput I hope it work for you
<input oninput="return event.target.value = event.target.value.replace(/[^0-9]/g,'')" type="text">

How to set maximum number of characters in number type textbox?

I have one textbox which is of number type. I want it to accept maximum of 16 digits, not more than that. For that I have tried with "maxlength" attribue and "max" attribute both. But its not working. Can anyone provide me solution?
<input type="number" id="dummy" max="16" />
Edit: I need to enter only whole number since it is used for account number of bank.
There are a few of these "how do I further control type="number" fields" questions here on SO. It boils down to:
You make it a type="number" and accept that you can't further mask the input vs. what the browser does to implement a numeric input, or
You make it type="text" and use pattern and/or maxlength to enforce the specific pattern you want, and accept that the browser won't add a specific UI for numbers.
Input type number doesn't support "maxlength" attribute. You can specify "max" attribute (HTML5), which is the highest number user can input. Something like this: <input type="number" max="999999999999" id="dummy" step="1" min="0">.
Edit: Also specify step attribute to 1.

AngularJs-Facing issue with ui-number-mask in Portuguese (Brazil) locale

My application locale is Portuguese (Brazil). In Brazil a dot (.) is used to separate thousands and comma(,) is used for decimal. Suppose user enters value 4.878 When user saves the data, it saves the correct value as entered in UI, but when next time page render it shows the round off value(i.e. 5 instead of 4.878). I am facing problem with numeric text box without decimal places,
<input class="inputbox" ng-model="value" ui-number-mask="0" />
If I set 2 decimal places for same textbox, then it will show/renders correct value always(i.e. 4.878,00):-
<input class="inputbox" ng-model="value" ui-number-mask="2" />
Any suggestion, why values are rounding off and how to fix this.
This sounds like a localization issue. Have you tried following this? https://docs.angularjs.org/guide/i18n

html regex validation limit only one period on decimal input

I made a HTML input which accepts decimal only.
<input type="text" class="form-control" id="price" name="price" placeholder="Price"
onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')">
This is working. However I need to modify the regex to accept only one period
Correct: 9.999
Wrong: 9.9.99.99
Is there a way? please don't use jquery validate and html type="number" (Users doesn't want the up and down arrow when you set the input to type number) Thanks
Sharing this answer to limit one period on decimal input
replace
this.value=this.value.replace(/[^0-9\.]/g,'')
with
this.value=this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')

HTML Field Type Input Number Only or Letter Only Without JavaScript

I create a form, where one field should only be filled with numbers.
I want that field can be filled only with numbers since entering input.
Like this example :
How Can I Use Javascript to Allow Only Numbers to Be Entered in a TextBox?
I've tried using Regex, but when I try to input is still able to enter letters.
<input type="number" min="2" pattern="^[0-9]" class="andi_input required-entry" name="amount" id="amount" required title='Only Number' />
I want it when input to field and not after click the Submit button and the message appear and inform that the field can only be filled with numbers.
I also try to add validate-number, but the result is the same.
How, without javascript, so that the field can only be filled with numbers or letters?
Whether for this kind of case have to use JavaScript or is there another way without JavaScript?
HTML 5 uses the type="number" so make sure that the browser that you are using is compatible. Check it out in action here.
You should check browser compatibility.
You're right with <input type="number" pattern="^[0-9]" />.
Your regex rule is :
^[0-9] :
^ assert position at start of the string
[0-9] match a single character present in the list below
(0-9 a single character in the range between 0 and 9)
You can check your regex here.
I use to use HTML5 Validation and jQuery one because IE is capricious most of the time.
UPDATE :
Without Javascript it's not possible to check pattern on real time. I suggest you to use a jQuery library like : http://www.jqueryscript.net/form/jQuery-Plugin-For-Formatting-User-Input-with-Specified-Pattern-formatter-js.html.
Here is a OneLiner:
<input type="number" onkeypress="return /[0-9]/i.test(event.key)">
or
<input type="text" onkeypress="return /[a-z]/i.test(event.key)">

Categories

Resources