Added validation for multiple decimal points
This commit is contained in:
parent
83c0e69637
commit
375b989322
|
@ -78,22 +78,32 @@
|
|||
})
|
||||
|
||||
.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() {
|
||||
var regex, error;
|
||||
var regex, error, decimalRegex;
|
||||
var checkDecimalNumbers = false;
|
||||
|
||||
if ( $( this ).is( '.wc_input_price' ) || $( this ).is( '#refund_amount' ) ) {
|
||||
checkDecimalNumbers = true;
|
||||
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' );
|
||||
decimalRegex = new RegExp( '[^\\' + woocommerce_admin.mon_decimal_point + ']', 'gi' );
|
||||
error = 'i18n_mon_decimal_error';
|
||||
} else if ( $( this ).is( '.wc_input_country_iso' ) ) {
|
||||
regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' );
|
||||
error = 'i18n_country_iso_error';
|
||||
} else {
|
||||
checkDecimalNumbers = true;
|
||||
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' );
|
||||
decimalRegex = new RegExp( '[^\\' + woocommerce_admin.decimal_point + ']', 'gi' );
|
||||
error = 'i18n_decimal_error';
|
||||
}
|
||||
|
||||
var value = $( this ).val();
|
||||
var newvalue = value.replace( regex, '' );
|
||||
|
||||
// Check if newvalue have more than one decimal point.
|
||||
if ( checkDecimalNumbers && 1 < newvalue.replace( decimalRegex, '' ).length ) {
|
||||
newvalue = newvalue.replace( decimalRegex, '' );
|
||||
}
|
||||
|
||||
if ( value !== newvalue ) {
|
||||
$( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), error ] );
|
||||
} else {
|
||||
|
|
|
@ -169,9 +169,9 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
|
|||
|
||||
$params = array(
|
||||
/* translators: %s: decimal */
|
||||
'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
|
||||
'i18n_decimal_error' => sprintf( __( 'Please enter with one decimal point (%s) without thousand separators.', 'woocommerce' ), $decimal ),
|
||||
/* translators: %s: price decimal separator */
|
||||
'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
|
||||
'i18n_mon_decimal_error' => sprintf( __( 'Please enter with one monetary decimal point (%s) without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
|
||||
'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
|
||||
'i18n_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
|
||||
'i18n_delete_product_notice' => __( 'This product has produced sales and may be linked to existing orders. Are you sure you want to delete it?', 'woocommerce' ),
|
||||
|
|
Loading…
Reference in New Issue