• antd 表单的两种校验方式


    1.声明式表单验证:

                            <Form.Item
                                name="username"
                                rules={[
                                    {
                                        required: true,
                                        message: 'Please input your Username!',
                                    },
                                    {
                                        max: 20,
                                        message: '最长20位!',
                                    },
                                    {
                                        min: 5,
                                        message: '至少5位!!',
                                    },                                {
                                        pattern: /^[A-Za-zd_]+$/,
                                        message: '自能包含字母数字下划线字符!',
                                    },
                                ]}
                            >
                                <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="Username" />
                            </Form.Item>
    

      

    2. validator自定义式验证:

                            <Form.Item
                                name="password"
                                rules={[
                                    {
                                        validator: (_, value) =>{
                                        if(value.length >= 6 && value.length<=10) {
                                            return Promise.resolve()
                                        }else{
                                            return Promise.reject('密码长度必须是6~10位')
                                        }
                                      }
                                    }
                                ]}
                            >
                                <Input
                                    prefix={<LockOutlined className="site-form-item-icon" />}
                                    type="password"
                                    placeholder="Password"
                                />
                            </Form.Item>
    

      

  • 相关阅读:
    javascript 与 asp.net 的交互
    10 Mar 10 Auto Complete Ajax Scripts
    Asp.net性能优化总结
    window.print(); is not working in Safari Browser Windows XP
    用VS.NET中的测试工具(Application Center Test)测试ASP.NET程序
    ASP.NET页面事件过程多个用户控件时的执行过程
    Swt/Jface treeViewer的使用
    批量引入struts标签简化引入操作
    android学习笔记47android_手势识别技术的实现,手势库的创建
    学校举行的ACM,有道题没弄明白!!
  • 原文地址:https://www.cnblogs.com/jlyuan/p/12774414.html
Copyright © 2020-2023  润新知