New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

antd-form-rules

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antd-form-rules

```bash yarn add antd-form-rules

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

安装

yarn add antd-form-rules

# 或者

npm install antd-form-rules --save

使用

import { FormRules } from 'antd-form-rules';

getFieldDecorator('id', {
   rules: FormRules.withName('字段名').isRequired().create(),
});

方法介绍

withName(fileName: string)

规则必须先初始化才能做链式调用

FormRules.withName('字段');
create()

生成的规则由该方法统一转换为antd需要的格式

FormRules.withName('字段').create();
isRequired(onlyWhiteSpaceIsError = true)

通用方法,用于强调前一个规则是必填的,不能跳过。

FormRules.withName('字段')
    .string(1, 15).isRequired()
    .match(/\w+/).isRequired()
    .create();

FormRules.withName('字段').string().isRequired().create();

如果isRequired前面没有规则,那么会默认添加一个string()的规则

FormRules.withName('字段').isRequired().create();
// 等于
FormRules.withName('字段').string().isRequired().create();
string(min?: number, max?: number, message?: string)

字符串规则,可自定义长度

FormRules.withName('字段').string().create();
FormRules.withName('字段').string(1, 15).create();
FormRules.withName('字段').string(20).create();
FormRules.withName('字段').string(undefined, 20).create();
bool(message?: string)

布尔值规则,常用于Radio

array(message?: string)

数组规则

phone(message?: string)

国内11位手机号

number(min?: number, max?: number, message?: string)

数字,包括小数、整数、负数、正数

FormRules.withName('字段').number().create();
FormRules.withName('字段').number(0.01, 1).create();
FormRules.withName('字段').number(0).create();
FormRules.withName('字段').number(undefined, 5).create();
integer(min?: number, max?: number, message?: string)

只能是整数

FormRules.withName('字段').integer().create();
FormRules.withName('字段').integer(1).create();
FormRules.withName('字段').integer(1, 5).create();
FormRules.withName('字段').integer(undefined, 5).create();
email(message?: string)

邮箱号规则

match(pattern: RegExp, message?: string)

正则匹配

FormRules.withName('字段').match(/\w\s*\w/).isRequired().create();
url(message?: string)

超链接规则

callback(fn: Function)

自定义规则

FormRules.withName('字段').callback((value, field) => {
   if (value !== '孙悟空') {
       return new Error('这个是六耳猕猴');
   }
}).create();
identityCard(message?: string)

第二代身份证

withoutWhiteSpace(message?: string)

禁止包含空格

object(message?: string)

数据必须是对象。如时间控件返回的是moment的对象

append(obj)

如果以上规则都不能满足你,那么可以用这个append直接添加antd的原生规则。或者欢迎issue

import { FormRuleType } from 'antd-form-rules';

FormRules.withName('字段').string().append({ required: true, type: FormRuleType.object }).create();

FAQs

Package last updated on 30 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc