Title: Force decimals in html inputs with InputMask html (jqueryl or js)?
Tags: javascript;jquery;html;regex
Question: I want to force my html input the following display: 14 mantissa maximun(from 1 to 14) and the Effective Three decimal point, if the user does not specify the value of the points after they take the default 000
Example: Enter 5  show   5.000
enter 5.2 Show 5.200
enter 22222 show 22222.000 display.
please help

Comment: how if the value 12-14 digit? became "123456789123.000"(became 15 digit long)?

Comment: Please show some effort. What have you tried?

Comment: @najeh22 I'm not even questioning that you have made an effort. I'm just asking you to show us your failed attempts, so we have something to improve on.

Comment: belive I made a lot of effort from yesterdays that I could get this solution to my problem because it is more complex than that , but a solution like this can be enough, I look everywhere but I did not find an answer .

Comment: in my data base table i have price numeric(16,3)

Comment: I tried first jquery inputmasque with the plugin digital bash , the problem is whith the optionanal value , i can't add  decimal 000 if I put only digital value, after that i passed to regex and i start creating my own expression but it doesn't work: like this var ex=/[0-9]{1-14}(\.[0-9]{3} |(\.000)$/;

Comment: I tried this but I still have problemes with it ,checkDec(el){ var ex=/^[0-9]{1,3}\.[0-9]{2}$/; if(ex.test(el.value)==false){ el.value = el.value.substring(0,el.value.length - 1); } } ,I use onkeyup in html.


Here is another answer: Use ```.indexOf``` to check for the ```.``` character. Make sure it's there and check the length of the ```substring``` that goes after its index. If it's less then 3, add some zeros.

HTML

```<input type="text" id="input" maxlength="14" value="" /&gt;
```

JavaScript

```/* Select the desired input, and add an onChange event listener */
document.querySelector('#input').onchange = function () {
    /* if the user didn't add a dot, we add one with 3 zeros */
    if (this.value.indexOf('.') == -1) this.value += '.000';

    /* Otherwise, we check how many numbers there are after the dot
       and make sure there's at least 3*/
    if (this.value.substring(this.value.indexOf('.') + 1).length < 3)
        while (this.value.substring(this.value.indexOf('.') + 1).length < 3)
            this.value += '0';
};
```

Live Demo

Comment for this answer: @najeh22 There are no regular expressions in my answer, so I don't know what your problem is. Also: [**How to accept an answer**](http://meta.stackexchange.com/a/971-791-2149).
Comment for this answer: What do you mean by "force the display of the real part" ? I don't see that part in your original question.
Comment for this answer: thank you, it 's fine, but i still have probleme with regular expression
Comment for this answer: your answer answers part of the question, but because of the other party which is not yet solved, my problem is not solved.
I need a regex expression to force the display of the real part, I tested the input mask with your solution, but it gives no good result.
Comment for this answer: I want to force my html input the following display: 14 digital maximun(from 1 to 14) and  Three decimal point.from 0.000 to 99999999999999.999
Comment for this answer: 14 numbers maximum before the point.
Comment for this answer: I find the solution http://jsfiddle.net/vandalo/fhYAs/

Here is another answer: 
check if the number match ```(\d{1,14})(\.\d{1,3}){0,1}```
split by .(dot) char
check the length of the second array result
add .000 if null or ajust if have 1 or 2 length by add 2 or 1 zero


Comment for this answer: [see this](http://jsfiddle.net/4BcF5/). i think that will be clear enough for you to get what you need. and i said `split(".")` not `substring()`
Comment for this answer: I tried this but I still have problemes with it ,checkDec(el){ var ex=/^[0-9]{1,3}\.[0-9]{2}$/; if(ex.test(el.value)==false){ el.value = el.value.substring(0,el.value.length - 1); } } ,I use onkeyup in html.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 7, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:08/16/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><jquery><html><regex>', 'Title': 'Force decimals in html inputs with InputMask html (jqueryl or js)?', 'ViewCount': 1067, 'id': 18273209, 'user_AboutMe': None, 'user_AccountId': 3099129.0, 'user_DisplayName': 'najeh22', 'user_Reputation': 221.0, 'user_Views': 62.0, 'user_id': 2623715.0}}