npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

antd-form-rules

v2.0.0

Published

```bash yarn add antd-form-rules

Downloads

12

Readme

安装

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();