|
61 | 61 | })
|
62 | 62 |
|
63 | 63 | .on( 'change', '.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text]', function() {
|
64 |
| - var regex; |
| 64 | + var regex, decimalRegex, |
| 65 | + decimailPoint = woocommerce_admin.decimal_point; |
65 | 66 |
|
66 | 67 | if ( $( this ).is( '.wc_input_price' ) || $( this ).is( '#refund_amount' ) ) {
|
67 |
| - regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' ); |
68 |
| - } else { |
69 |
| - regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' ); |
| 68 | + decimailPoint = woocommerce_admin.mon_decimal_point; |
70 | 69 | }
|
71 | 70 |
|
| 71 | + regex = new RegExp( '[^\-0-9\%\\' + decimailPoint + ']+', 'gi' ); |
| 72 | + decimalRegex = new RegExp( '\\' + decimailPoint + '+', 'gi' ); |
| 73 | + |
72 | 74 | var value = $( this ).val();
|
73 |
| - var newvalue = value.replace( regex, '' ); |
| 75 | + var newvalue = value.replace( regex, '' ).replace( decimalRegex, decimailPoint ); |
74 | 76 |
|
75 | 77 | if ( value !== newvalue ) {
|
76 | 78 | $( this ).val( newvalue );
|
77 | 79 | }
|
78 | 80 | })
|
79 | 81 |
|
80 | 82 | .on( 'keyup', '.wc_input_price[type=text], .wc_input_decimal[type=text], .wc_input_country_iso[type=text], .wc-order-totals #refund_amount[type=text]', function() {
|
81 |
| - var regex, error; |
| 83 | + var regex, error, decimalRegex; |
| 84 | + var checkDecimalNumbers = false; |
82 | 85 |
|
83 | 86 | if ( $( this ).is( '.wc_input_price' ) || $( this ).is( '#refund_amount' ) ) {
|
| 87 | + checkDecimalNumbers = true; |
84 | 88 | regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' );
|
| 89 | + decimalRegex = new RegExp( '[^\\' + woocommerce_admin.mon_decimal_point + ']', 'gi' ); |
85 | 90 | error = 'i18n_mon_decimal_error';
|
86 | 91 | } else if ( $( this ).is( '.wc_input_country_iso' ) ) {
|
87 | 92 | regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' );
|
88 | 93 | error = 'i18n_country_iso_error';
|
89 | 94 | } else {
|
| 95 | + checkDecimalNumbers = true; |
90 | 96 | regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' );
|
| 97 | + decimalRegex = new RegExp( '[^\\' + woocommerce_admin.decimal_point + ']', 'gi' ); |
91 | 98 | error = 'i18n_decimal_error';
|
92 | 99 | }
|
93 | 100 |
|
94 | 101 | var value = $( this ).val();
|
95 | 102 | var newvalue = value.replace( regex, '' );
|
96 | 103 |
|
| 104 | + // Check if newvalue have more than one decimal point. |
| 105 | + if ( checkDecimalNumbers && 1 < newvalue.replace( decimalRegex, '' ).length ) { |
| 106 | + newvalue = newvalue.replace( decimalRegex, '' ); |
| 107 | + } |
| 108 | + |
97 | 109 | if ( value !== newvalue ) {
|
98 | 110 | $( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), error ] );
|
99 | 111 | } else {
|
|
0 commit comments