zoukankan      html  css  js  c++  java
  • iview表单验证数字

    验证输入字符串必须为数字

    html:

                    <FormItem label="兑换积分:" prop="exchangeIntegral">
                        <Input v-model="formSpecAdd.exchangeIntegral" placeholder="请输入兑换积分" style=" 250px"></Input>
                    </FormItem>
    
    
                    <FormItem label="库存数量:" prop="stockNum">
                        <Input v-model="formSpecAdd.stockNum" placeholder="请输入库存数量" style=" 250px"></Input>
                    </FormItem>
    
    
                    <FormItem label="商品价值:" prop="productMoney">
                        <Input v-model="formSpecAdd.productMoney" placeholder="请输入商品价值" style=" 250px"></Input>
                    </FormItem>

    js:

                        exchangeIntegral: [
                            {required: true, message: '请输入兑换积分', trigger: 'blur'},
                            {type: 'string', pattern: /^d+$/, message: '请输入数字', trigger: 'blur'}
                        ],
    
                        stockNum: [
                            {required: true, message: '请输入库存数量', trigger: 'blur'},
                            {type: 'string', pattern: /^d+$/, message: '请输入数字', trigger: 'blur'}
                        ],
    
                        productMoney: [
                            {required: true, message: '请输入商品价值', trigger: 'blur'},
                            {type: 'string', pattern: /^d+$/, message: '请输入数字', trigger: 'blur'}
                        ],

    或者: 直接将输入框定义为 number类型

                    <FormItem label="兑换积分:" prop="exchangeIntegral">
                        <Input v-model="formSpecAdd.exchangeIntegral" number placeholder="请输入兑换积分" style=" 250px"></Input>
                    </FormItem>

    js:验证

                        exchangeIntegral: [
                            {required: true, type: 'number', message: '请输入兑换积分', trigger: 'blur'},
                            {type: 'number', message: '请输入数字', trigger: 'blur'}
                        ],

    请参考:

    https://www.cnblogs.com/chenmz1995/p/10804076.html

    https://www.iviewui.com/components/form#ZDYYZ

    https://github.com/yiminghe/async-validator

  • 相关阅读:
    printf和sprintf
    操作数、运算符、表达式
    全自动加法机
    Ascll、GB2312、Ansi
    数组
    循环
    编程命名规范
    浮点数及缺陷
    Android编码规范
    RGB着色对照表
  • 原文地址:https://www.cnblogs.com/taohuaya/p/11030202.html
Copyright © 2011-2022 走看看