{"id":22771697,"url":"https://github.com/manweill/mobx-form-validator","last_synced_at":"2025-04-15T05:30:11.784Z","repository":{"id":57299619,"uuid":"86666186","full_name":"Manweill/mobx-form-validator","owner":"Manweill","description":"mobx-form-validator","archived":false,"fork":false,"pushed_at":"2017-11-08T02:37:07.000Z","size":33,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T16:21:22.536Z","etag":null,"topics":["mobx","mobx-form","react","react-native","validator"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Manweill.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.MD","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-30T06:17:40.000Z","updated_at":"2017-10-25T02:54:30.000Z","dependencies_parsed_at":"2022-08-26T20:24:39.285Z","dependency_job_id":null,"html_url":"https://github.com/Manweill/mobx-form-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Manweill%2Fmobx-form-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Manweill%2Fmobx-form-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Manweill%2Fmobx-form-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Manweill%2Fmobx-form-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Manweill","download_url":"https://codeload.github.com/Manweill/mobx-form-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249014371,"owners_count":21198585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mobx","mobx-form","react","react-native","validator"],"created_at":"2024-12-11T16:16:45.035Z","updated_at":"2025-04-15T05:30:11.759Z","avatar_url":"https://github.com/Manweill.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mobx-form-validator\n\n### base on [mobx-form-validate](https://github.com/tdzl2003/mobx-form-validate) and [validator](https://github.com/chriso/validator.js)\n\n## Installation\n\nnpm i mobx-form-validator\nor\nyarn add mobx-form-validator\n\n## Usage\n\n```js\nimport validator from 'mobx-form-validator';\n\nclass TestModel{\n  @observable\n  @validator([\n    {reg1,reg2,reg3,message},\n    {reg1,reg2,reg3,message}\n    ...\n  ])\n  name=''\n}\n```\n### Explame\n\n```js\n\nexport default class RegisterForm {\n  @observable\n  @validator([{\n    required: true\n  }])\n  userName = ''\n\n  @observable\n  nickName = ''\n\n  @observable\n  @validator([{\n    required: true, lengths: [1, 15], message: '请输入1-15位的密码！'\n  }])\n  password = ''\n\n  @observable\n  @validator([{\n    custom: (target, targetValue, source) =\u003e {\n      if (targetValue != source.password) {\n        return message = '两次输入的密码不一样'\n      }\n    }\n  }])\n  passwordConfirm = ''\n\n\n  @observable\n  @validator([{\n    required: true, message: \"请输入邮箱地址\"\n  }, {\n    type: 'Email', message: '请输入正确的邮箱地址！'\n  }])\n  email = ''\n\n  @observable\n  @validator([{\n    pattern: /^1[3578]\\d{9}$/, message: '请输入正确的手机号码！'\n  }])\n  mobilePhone = ''\n\n  @observable\n  @validator([{\n     max: 200, min: 0, message: '年龄介乎0~200之间！'\n  }])\n  age = ''\n\nconst form = new RegisterForm();\nconsole.log(form.validateErrorUserName);          // userName is required\nconsole.log(form.validateErrorPassword);          // 请输入1-15位的密码\nconsole.log(form.validateErrorPasswordConfirm);   // 两次输入的密码不一样\nconsole.log(form.validateErrorEmail);             // 请输入正确的邮箱地址！\nconsole.log(form.validateErrorMobilePhone);       // 请输入正确的手机号码！\nconsole.log(form.validateErrorAge);               // 年龄介乎0~200之间！\nconsole.log(form.isValid);                        // false\n```\n\n\n## API\n\n|参数      | 说明                                            | 类型 \n|---|---|---\n|beforeValidate    | 校验前转换,返回要转换的值，如果返回空，则取当前值   |  (value) =\u003e any\n|compare   | 与当前对象的某一字段进行全等对比                   | string\n|[custom](#custom)    | 自定义校验，返回错误信息，如果为空则认为校验成功    | (target, targetValue, source) =\u003e string \\| undefined\n|lengths   | 字符串货数组长度 eg: length:[6,15]               | number[]\n|max       | 最大值                                          | number\n|message   | 提示信息                                        | string\n|min       | 最小值                                          | number\n|pattern   | 正则表达式                                      | RegExp\n|required  | 是否必填                                        | boolean\n|type      | 数据类型                                        | [Enum Types](#enum-types)\n\n### Enum Types\n\n`Ascii` `Base64`  `Boolean` `CreditCard`  `Currency`  `DataURI` `Decimal` `Email` `Float` `HexColor`  `Hexadecimal` `IP`  `Int` `JSON`  `MACAddress`  `Numeric` `URL` `UUID`\n\n\n### custom\n\n``` js\n /**\n   * 自定义校验，返回错误信息，如果为空则认为校验成功\n   * @param target 要校验的属性字段\n   * @param targetValue 要检验的值\n   * @param source 要校验的属性所属的对象\n   */\n  custom: (target, targetValue, source) =\u003e string | undefined;\n```\n\n## Change Log\n\n## 1.3.2\n`2017-11-08`\n- add before method rename to beforeValidate\n- fix Enum Type\n- fix index.d.ts pathc\n\n## 1.3.0\n`2017-08-10`\n- Features\n  - add compore method","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanweill%2Fmobx-form-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanweill%2Fmobx-form-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanweill%2Fmobx-form-validator/lists"}