The el-input input verification cannot be a space, and all empty content cannot be entered

Application scenario:

The verification of the input box is too common. Basically, the common ones are: cannot be empty, cannot enter spaces, and cannot enter all empty content. This is documented here.


Detailed development:

Shown separately for three situations:

 rules: {
      ResearchNO: [
        { required: true, message: '请输入项目代码', trigger: 'blur' },
        {
          required: true,
          transform: (value) => value && value.trim(),
          message: '项目代码不能全部为空',
          trigger: 'blur'
        }
      ],
      Name: [
        //输入为空
        { required: true, message: '请输入项目名称', trigger: 'blur' },
        {
          min: 1,
          max: 50,
          message: '长度在 1 到 50 个字符',
          trigger: 'blur'
        },
        //不能全部输入空格
        {
          required: true,
          transform: (value) => value && value.trim(),
          message: '项目名称不能全部为空',
          trigger: 'blur'
        }
      ]
    },

You cannot enter all spaces, mainly because it works here:

 {
          required: true,
          transform: (value) => value && value.trim(),
          message: '项目名称不能全部为空',
          trigger: 'blur'
        }

 

There is also no space to enter: add trim after v-model

 <el-form-item label="项目名称" prop="Name">
          <el-input v-model.trim="projectInfo.Name" placeholder="请输入项目名称"></el-input>
        </el-form-item>

Analyzed:

The above is for the record.

 

Guess you like

Origin blog.csdn.net/ParkChanyelo/article/details/128584172