可以编写angularjs的自定义指令来实现验证文本框填入的数值是来为小数。

自定义验证小数数值_isEmpty

 

自定义验证小数数值_isEmpty_02自定义验证小数数值_directive_03
airExpressApp.directive('validateDecimalCharacters', function () {

    var REQUIRED_PATTERNS = [
      /^-?[0-9]\d*(\.\d+)?$/
    ];

    return {
        require: 'ngModel',
        link: function ($scope, element, attributes, ngModelController) {

            ngModelController.$validators.validateDecimalCharacters = function (modelValue, viewValue) {
                var status = true;
                if (!ngModelController.$isEmpty(modelValue)) {
                    angular.forEach(REQUIRED_PATTERNS, function (pattern) {
                        status = status && pattern.test(modelValue);
                    });
                }
                return status;
            };
        }
    }
});
Source Code


自定义验证小数数值_directive_04


演示:
自定义验证小数数值_directive_05