Added sanitization for number of decimal points in JS

This commit is contained in:
Claudio Sanches 2019-08-02 14:02:33 -03:00
parent 375b989322
commit 2b0fc6f50a
1 changed files with 8 additions and 4 deletions

View File

@ -61,16 +61,20 @@
})
.on( 'change', '.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text]', function() {
var regex;
var regex, decimalRegex, decimailPoint;
if ( $( this ).is( '.wc_input_price' ) || $( this ).is( '#refund_amount' ) ) {
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' );
decimailPoint = woocommerce_admin.mon_decimal_point;
regex = new RegExp( '[^\-0-9\%\\' + decimailPoint + ']+', 'gi' );
decimalRegex = new RegExp( '\\' + decimailPoint + '+', 'gi' );
} else {
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' );
decimailPoint = woocommerce_admin.decimal_point;
regex = new RegExp( '[^\-0-9\%\\' + decimailPoint + ']+', 'gi' );
decimalRegex = new RegExp( '\\' + decimailPoint + '+', 'gi' );
}
var value = $( this ).val();
var newvalue = value.replace( regex, '' );
var newvalue = value.replace( regex, '' ).replace( decimalRegex, decimailPoint );
if ( value !== newvalue ) {
$( this ).val( newvalue );