vue数字校验-小数/范围/排除e


数字校验/可输入小数/排除e

<el-input type="number" v-model="aa" />

校验数字范围

const validateAcquaintance = (rule, value, callback) => {
  if (value < 0 ) {
    callback(new Error('请输入大于零的数字!'))
  } else {
    callback()
  }
}
data() {
    return {
		rules: {
		     aa: [
		       { required: true, message: '必填', trigger: 'change' }.
		       {validator: validateAcquaintance,trigger: 'blur'}
		     ]
		}
	}
}

仅仅是要求输入正整数

data() {
    return {
		rules: {
		     aa: [
		       { required: true, message: '必填', trigger: 'change' }.
		       { pattern:/^[0-9]*$/, message: '请输入数字' }
		     ]
		}
	}
}
Logo

前往低代码交流专区

更多推荐