antd 表單輸入立即校驗和點擊確認按鈕校驗


輸入立即校驗格式:

        <FormItem label='數據值' required={false}>
              {getFieldDecorator('accountValue', {
                validateTrigger: ['onChange', 'onBlur'],
                initialValue: undefined,
                validateFirst: true,
                rules: [
                  {
                    pattern: type === '1020003' && REG_IMSI,
                    message: '請輸入正確的IMSI',
                  },
                  {
                    pattern: type === '1020004' && REG_MOBILE,
                    message: '請輸入正確的手機號',
                  },
                  {
                    pattern: type === '1020002' && REG_MAC,
                    message: '請輸入正確的MAC',
                  },
                  {
                    pattern: type === '1030036' && REG_WX,
                    message: '請輸入正確的微信',
                  },
                  {
                    pattern: type === '1030001' && REG_QQ,
                    message: '請輸入正確的QQ',
                  },
                  {
                    pattern: type === '1021901' && REG_IMEI,
                    message: '請輸入正確的IMEI',
                  },
                  {
                    pattern: type === '1330000' && REG_WEIBO,
                    message: '請輸入正確的微博',
                  },
                ],
              })(<Input
                autoComplete="off"
                addonAfter={
                  getFieldDecorator('accountType', {
                    initialValue: type || undefined,
                    onChange: this.accountTypeChange.bind(this),
                  })(
                    <Select style={{width: 80}}>
                      <Option value="1020003">IMSI</Option>
                      <Option value="1020004">手機號</Option>
                      <Option value="1021901">IMEI</Option>
                      <Option value="1020002">MAC</Option>
                      <Option value="1030036">微信</Option>
                      <Option value="1030001">QQ</Option>
                      <Option value="1330000">微博</Option>
                    </Select>
                  )}
                style={{ width: '100%', marginRight: 8 }}
                placeholder="請輸入數據值"
                allowClear
              />)}
            </FormItem>

點擊確認按鈕進行格式校驗:

            <FormItem label='數據值' required={false}>
              {getFieldDecorator('accountValue', {
                validateTrigger: ['onSubmit'],
                initialValue: undefined,
                validateFirst: false,
                rules: [
                  {
                    pattern: type === '1020003' && REG_IMSI,
                    message: '請輸入正確的IMSI',
                  },
                  {
                    pattern: type === '1020004' && REG_MOBILE,
                    message: '請輸入正確的手機號',
                  },
                  {
                    pattern: type === '1020002' && REG_MAC,
                    message: '請輸入正確的MAC',
                  },
                  {
                    pattern: type === '1030036' && REG_WX,
                    message: '請輸入正確的微信',
                  },
                  {
                    pattern: type === '1030001' && REG_QQ,
                    message: '請輸入正確的QQ',
                  },
                  {
                    pattern: type === '1021901' && REG_IMEI,
                    message: '請輸入正確的IMEI',
                  },
                  {
                    pattern: type === '1330000' && REG_WEIBO,
                    message: '請輸入正確的微博',
                  },
                ],
              })(<Input
                autoComplete="off"
                addonAfter={
                  getFieldDecorator('accountType', {
                    initialValue: type || undefined,
                    onChange: this.accountTypeChange.bind(this),
                  })(
                    <Select style={{width: 80}}>
                      <Option value="1020003">IMSI</Option>
                      <Option value="1020004">手機號</Option>
                      <Option value="1021901">IMEI</Option>
                      <Option value="1020002">MAC</Option>
                      <Option value="1030036">微信</Option>
                      <Option value="1030001">QQ</Option>
                      <Option value="1330000">微博</Option>
                    </Select>
                  )}
                style={{ width: '100%', marginRight: 8 }}
                placeholder="請輸入數據值"
                allowClear
              />)}
            </FormItem>        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM