There is a validation /^\d+$/ she does not miss the amount in the form of 1000.00 (with a dot does not miss). How to make, that passed in the form of 1.00 , 1000.00 and so on?

    4 answers 4

    Java or JavaScript? Syntax - jQuery.

    Do not confuse java and javascript

     /^[\d]+(\.[\d]+)?$/.test('#price'); // попробуй 

      If strictly 2 decimal places:

       /^\d+(\.\d\d)?$/ 

      If an arbitrary amount:

       /^\d+(\.\d+)?$/ 
         /^(?=.*\d)\d*(?:\.\d{0,2})?$/ 

         (/^(?=.*\d)\d*(?:\.\d{0,2})?$/g).test('1'); //true (/^(?=.*\d)\d*(?:\.\d{0,2})?$/g).test('1.002'); //false (/^(?=.*\d)\d*(?:\.\d{0,2})?$/g).test('1.2'); //true (/^(?=.*\d)\d*(?:\.\d{0,2})?$/g).test('1.22'); //true 

          Thank you all so much for your help, thanks to this decision.

           /^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)(?:\\.\\d+)?$/