Search code examples
javascripthtmlregexmask

JavaScript Regular Expression for Money non JQuery


I need a money mask for an input, the problem is that I can't use jquery on my application.

How can I do this using regular expression 'on key up' for example?

here is my code:

<tr>
    <td>
        money:
            <input type="text" class="money"  maxlength="22" id="money" name="money">
        </td>
    </tr>

I the format to look like like 00.000,00


Solution

  • Try something like this

    There is a problem with trying to validate text as it's being typed which can be illustrated with this http://jsfiddle.net/denomales/dgeH2/. As the text field is updated if the current string matches or not will be displayed directly below.

    • ^[0-9]{1,3}(?:\.[0-9]{3})*(?:\,[0-9]{2})?$ will match currency in the format 00.000,00 as requested in the comments

    enter image description here

    • ^[0-9]{1,3}(?:\,[0-9]{3})*(?:\.[0-9]{2})?$ will match currency in the format 00,000.00

    enter image description here