input只能输入数字与小数点并且是0.25的倍数:
$('#input').on('keyup', function() {
const value = $(this).val();
let replaceVal = value.replace(/[^0-9.]/g, '');//输入的值只能为数字与小数点
if (replaceVal.length === 1 && replaceVal === '0') {//第一位数字不能为0,为0时自动清空
replaceVal = '';
}
$(this).val(replaceVal);
//这行对数据+字母无效: const regex = /\b[0-9]+\.(?:25|5|75)|(?<!\.|\d)[1-9]\d*(?!\.)/;
// if (!regex.test(replaceVal)) {
if (replaceVal % 0.25 !== 0) {//输入的数字必须是0.25的倍数
$('.error-msg').html(Drupal.t('Please enter a multiple 0f 0.25.'));
}
})