Method 1 : It is realized by regular expression
<template> <div> <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label
-width="100px" class="demo-ruleForm"> <el-row> <el-col :span="6"> <el-form-item
label=" amount of money " prop="money"> <el-input v-model.number="ruleForm.money"></el-input> <
/el-form-item> </el-col> </el-row> <el-row> <el-col :span="6" style=
"text-align:center"> <el-form-item> <el-button type="primary" @click=
"submitForm('ruleForm')"> Submit </el-button> </el-form-item> </el-col> </el-row> </el
-form> </div> </template> <script> export default { data() { return { ruleForm:
{ money:'', }, rules: { money:[ { required: true, message: ' Amount cannot be blank '}, { type:
'number', message: ' Amount must be numeric '}, // And does not include decimals { pattern:
/^([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/, message: ' The scope is 0-255',trigger: 'blur'}
/* Range 0-255 analysis : 0-9: [0-9] 10-99: [1-9]\d 100-199: 1\d\d 200-249: 2[0-4]\d
250-255: 25[0-5] */ ], } }; }, methods: { submitForm(formName) { this.$refs[
formName].validate((valid) => { if (valid) { alert(' success '); } else { return false;
} }); }, } } </script>
supplement : Regular expression related knowledge points

Method 2 : User defined verification rules
<template> <div> <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label
-width="100px" class="demo-ruleForm"> <el-row> <el-col :span="6"> <el-form-item
label=" amount of money " prop="money"> <el-input v-model.number="ruleForm.money"></el-input> <
/el-form-item> </el-col> </el-row> <el-row> <el-col :span="6" style=
"text-align:center"> <el-form-item> <el-button type="primary" @click=
"submitForm('ruleForm')"> Submit </el-button> </el-form-item> </el-col> </el-row> </el
-form> </div> </template> <script> export default { data() { var checkMoney = (
rule, value, callback) => { if (!value) { return callback(new Error(' Amount cannot be blank '));
} setTimeout(() => { if (!Number.isInteger(value)) { callback(new Error(' Please enter a numeric value '
)); } else { if (value < 0) { callback(new Error(' The scope is 0-255')); } else if(value >
255){ callback(new Error(' The scope is 0-255')); }else { callback(); } } }, 100); };
return { ruleForm: { money:'', }, rules: { money:[ { validator: checkMoney,
trigger: 'blur' } ], } }; }, methods: { submitForm(formName) { this.$refs[
formName].validate((valid) => { if (valid) { alert(' success '); } else { return false;
} }); }, } } </script>
effect

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?