Показать сообщение отдельно
  #4 (permalink)  
Старый 20.08.2018, 16:58
Новичок на форуме
Отправить личное сообщение для xecic Посмотреть профиль Найти все сообщения от xecic
 
Регистрация: 20.08.2018
Сообщений: 4

Сообщение от ksa Посмотреть сообщение
Как вариант...

var re=/^\-?\d*?(\.\d+)?/;
alert(re.test('123'));
alert(re.test('0.123'));
alert(re.test('.123'));
alert(re.test('1.23'));
alert(re.test('-1.56'));
alert(re.test('-5'));
Так?
$( document ).ready(function() {
  var AX;
  var re=/^\-?\d*?(\.\d+)?/;

  $("#AXInput").on("keypress keyup blur",function (event) {
     AX = re.test($(this));
  });
});

Или так
$( document ).ready(function() {
  $("#AXInput").on("keypress keyup blur",function (event) {
             //this.value = this.value.replace(/[^0-9\.]/g,'');
      $(this).val($(this).val().replace(/^\-?\d*?(\.\d+)?/,''));
             if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
                 event.preventDefault();
             }
         });
  });

Не получается, что то.

Последний раз редактировалось xecic, 20.08.2018 в 17:27.
Ответить с цитированием