域和组件级别的验证 vadacl

码农软件 · 软件分类 · 验证码(Captcha) · 2019-04-22 09:28:24

软件介绍

vadacl ("validation at domain and component levels")是一个基于 TypeScript 的代码库,能提高 Angular 2 形式类验证功能。它提供了一种方法让开发人员可以对数据对象设置基于域或数据库的验证规则,然后在不同的组件需要的时候增加或替换这些验证。它还可以让开发人员添加和重写那些已添加的验证错误消息,验证方法返回验证元数据中。

示例代码:

import { Validatable, PropertyValidations } from '../vadacl/interfaces'
export class UserProfile implements Validatable {
    firstName: string = null;
    lastName: string = null;
    username: string = null;
    age: number = null;
    gender: string = null;
    validations: { [ index: string ] : PropertyValidations } = {
        firstName: {
            maxLength: { maxLength: 25, message: 'Your first name cannot be longer than 25 characters.'},
            required: { message: 'Your first name is required.' }
        },
        lastName: {
            maxLength: { maxLength: 25, message: 'Your last name cannot be longer than 25 characters.'},
            required: { message: 'Your last name is required.' }
        },
        username: {
            maxLength: { maxLength: 30, message: 'Your username cannot be longer than 25 characters.'},
            required: { message: 'You must have a username.' }
        },
        age: {
            pattern: { pattern: '[0-9]*', message: 'Enter your age as an integer.' }
        },
        gender: {
            pattern: { pattern: 'M|F', message: 'Enter your gender as "M" or "F".' }
        }
    };
}

未来发展:

  • 添加单元测试。

  • 增加更多的验证方法。

  • 添加在消息模块中设置域级验证错误消息的能力,以适应国际化。

本文地址:https://codercto.com/soft/d/4122.html

Web Development Recipes

Web Development Recipes

Brian P. Hogan、Chris Warren、Mike Weber、Chris Johnson、Aaron Godin / Pragmatic Bookshelf / 2012-1-22 / USD 35.00

You'll see a full spectrum of cutting-edge web development techniques, from UI and eye candy recipes to solutions for data analysis, testing, and web hosting. Make buttons and content stand out with s......一起来看看 《Web Development Recipes》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具