本文整理汇总了TypeScript中aurelia-validation.ValidationRules类的典型用法代码示例。如果您正苦于以下问题:TypeScript ValidationRules类的具体用法?TypeScript ValidationRules怎么用?TypeScript ValidationRules使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ValidationRules类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: add
add() {
// minimum
ValidationRules
.customRule(
'minimum',
(val, _obj, min) => val !== undefined ? val >= min : true,
this.configuration.messages.minimum || '${$displayName} must be greater than or equal to ${$config.min}.',
(min) => ({ min })
);
// exclusionMinimum
ValidationRules
.customRule(
'exclusiveMinimum',
(val, _obj, min) => val !== undefined ? val > min : true,
this.configuration.messages.exclusiveMinimum || '${$displayName} must be greater than ${$config.min}.',
(min) => ({ min })
);
// maximum
ValidationRules
.customRule(
'maximum',
(val, _obj, max) => val !== undefined ? val <= max : true,
this.configuration.messages.maximum || '${$displayName} must be less than or equal to ${$config.max}.',
(max) => ({ max })
);
// exclusiveMaximum
ValidationRules
.customRule(
'exclusiveMaximum',
(val, _obj, max) => val !== undefined ? val < max : true,
this.configuration.messages.exclusiveMaximum || '${$displayName} must be less than ${$config.max}.',
(max) => ({ max })
);
// multipleOf
ValidationRules
.customRule(
'multipleOf',
(val, _obj, multiple) => val !== undefined ? ((val % multiple) / 100) === 0 : true,
this.configuration.messages.multipleOf || '${$displayName} must be a multiple of ${$config.multiple}.',
(multiple) => ({ multiple })
);
}
开发者ID:jbockle,项目名称:aurelia-json-schema-form,代码行数:46,代码来源:number-rules.ts
示例2: configureValidations
configureValidations() {
ValidationRules.customRule(
'integerRange',
(value, obj, min, max) => {
var num = Number.parseInt(value);
return num === null || num === undefined || (Number.isInteger(num) && num >= min && num <= max);
},
"${$displayName} must be an integer between ${$config.min} and ${$config.max}.",
(min, max) => ({ min, max })
);
}
开发者ID:NickSchweitzer,项目名称:SumpPumpMonitor,代码行数:11,代码来源:app.ts
示例3:
.then(data => {
this.pump = data;
ValidationRules
.ensure((pc: PumpConfiguration) => pc.name)
.displayName('Sump Pump Name')
.required()
.ensure((pc: PumpConfiguration) => pc.maxWaterLevel)
.displayName('Maximum Water Level')
.required()
.satisfiesRule('integerRange', 0, 15)
.ensure((pc: PumpConfiguration) => pc.maxRunTimeNoChange)
.displayName('Maximum Time of No Water Level Change')
.required()
.satisfiesRule('integerRange', 0, 60)
.on(this.pump.desired);
});
开发者ID:NickSchweitzer,项目名称:SumpPumpMonitor,代码行数:17,代码来源:pumpedit.ts
示例4: bind
bind(ctrl: SfArray) {
let rule = ValidationRules
.ensureObject()
.displayName(ctrl.form.$schema.title)
.satisfies(() => true);
if (ctrl.form.$required) {
rule = rule.required();
}
if (Number.isInteger(ctrl.form.$schema.maxItems)) {
rule = rule.maxItems(ctrl.form.$schema.maxItems);
}
if (Number.isInteger(ctrl.form.$schema.minItems)) {
rule = rule.minItems(ctrl.form.$schema.minItems);
}
if (ctrl.form.$schema.uniqueItems) {
// TODO: add unique items rule
}
rule.on(ctrl.model);
}
开发者ID:jbockle,项目名称:aurelia-json-schema-form,代码行数:19,代码来源:array-rules.ts
示例5: configure
export function configure(config: FrameworkConfiguration, configCallback) {
config.container.registerHandler('ui-validator', container => container.get(UIValidationRenderer));
config.globalResources([
'./elements/core/ui-viewport',
'./elements/core/ui-page',
'./elements/core/ui-grid'
]);
config.globalResources([
'./elements/components/ui-tab',
'./elements/components/ui-menu',
'./elements/components/ui-panel',
'./elements/components/ui-drawer',
'./elements/components/ui-tree',
'./elements/components/ui-datagrid'
]);
config.globalResources([
'./elements/inputs/ui-button',
'./elements/inputs/ui-input',
'./elements/inputs/ui-option',
'./elements/inputs/ui-markdown',
'./elements/inputs/ui-list',
'./elements/inputs/ui-date'
]);
config.globalResources([
'./attributes/ui-marked',
'./attributes/ui-badge'
]);
config.globalResources([
'./value-converters/ui-text',
'./value-converters/ui-lodash'
]);
var Configure = {
title: (t) => {
UIConstants.App.Title = t;
return Configure;
},
version: (t) => {
UIConstants.App.Version = t;
return Configure;
},
appKey: (t) => {
UIConstants.App.Key = t;
return Configure;
},
apiUrl: (t) => {
UIConstants.Http.BaseUrl = t;
return Configure;
},
apiHeaders: (t) => {
UIConstants.Http.Headers = t;
return Configure;
},
sendAuthHeader: (t) => {
UIConstants.Http.AuthorizationHeader = t;
return Configure;
},
languages: (l) => {
UIConstants.Languages = l;
return Configure;
}
};
if (configCallback !== undefined && typeof configCallback === 'function') {
configCallback(Configure);
}
// Validation Rules
ValidationRules
.customRule('phone', (value, obj) => value === null || value === undefined || value === '' || PhoneLib.isValid(value), '\${$displayName } is not a valid phone number.');
ValidationRules
.customRule('integer', (value, obj, min, max) => value === null || value === undefined || value === '' || (Number.isInteger(value) && value >= (isEmpty(min) ? Number.MIN_VALUE : min) && value <= (isEmpty(max) ? Number.MAX_VALUE : max)),
'\${$displayName} must be an integer value between \${$config.min} and \${$config.max}.', (min, max) => ({ min, max }));
ValidationRules
.customRule('decimal', (value, obj, min, max) => value === null || value === undefined || value === '' || (isNumber(value) && Math.floor(value % 1) === 0 && value >= (isEmpty(min) ? Number.MIN_VALUE : min) && value <= (isEmpty(max) ? Number.MAX_VALUE : max)),
'\${$displayName} must be a decimal value between \${$config.min} and \${$config.max}.', (min, max) => ({ min, max }));
ValidationRules
.customRule('language', (map, obj, controller, langInput) => {
if (!(langInput && langInput.addError && langInput.removeError)) throw new Error('Language validation must have reference to ui-language');
let promises = [];
_.forEach(map, (model, key) => {
promises.push(controller.validator.validateObject(model)
.then(e => {
if (langInput.errors.indexOf(key) > -1) langInput.removeError(key);
if (e.length > 0) langInput.addError(key);
return e.length > 0 ? true : false;
}));
});
return Promise.all(promises).then(e => _.filter(e).length == 0);
}, 'Some language entries contain invalid values');
// Setup kramed
let rend = new kramed.Renderer();
rend.code = (code, lang) => {
if (window.hljs) {
window.hljs.configure({
useBR: true,
tabReplace: ' '
});
//.........这里部分代码省略.........
开发者ID:sigmaframeworks,项目名称:sigma-ui-framework,代码行数:101,代码来源:index.ts
示例6: add
add() {
// format datetime
// tslint:disable-next-line:max-line-length
const iso8601Datetime = /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i;
ValidationRules
.customRule(
'format_datetime',
(val: string) => !!val ? iso8601Datetime.test(val) : true,
this.configuration.messages.format_datetime || '${$displayName} is not a valid date/time.'
);
// format date
const iso8601Date = /^\d\d\d\d-[0-1]\d-[0-3]\d$/;
ValidationRules
.customRule(
'format_date',
(val: string) => !!val ? iso8601Date.test(val) : true,
this.configuration.messages.format_date || '${$displayName} is not a valid date.'
);
// format time
const iso8601Time = /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i;
ValidationRules
.customRule(
'format_time',
(val: string) => !!val ? iso8601Time.test(val) : true,
this.configuration.messages.format_time || '${$displayName} is not a valid time.'
);
// format ipv4
const ipv4 = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
ValidationRules
.customRule(
'format_ipv4',
(val: string) => !!val ? ipv4.test(val) : true,
this.configuration.messages.format_ipv4 || '${$displayName} is not a valid IPv4 address.'
);
// format ipv6
// tslint:disable-next-line:max-line-length
const ipv6 = /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i;
ValidationRules
.customRule(
'format_ipv6',
(val: string) => !!val ? ipv6.test(val) : true,
this.configuration.messages.format_ipv6 || '${$displayName} is not a valid IPv6 address.'
);
// format hostname
const hostname = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i;
ValidationRules
.customRule(
'format_hostname',
(val: string) => !!val ? hostname.test(val) : true,
this.configuration.messages.format_hostname || '${$displayName} is not a valid hostname.'
);
// format uri
const uri = /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i;
ValidationRules
.customRule(
'format_uri',
(val: string) => !!val ? uri.test(val) : true,
this.configuration.messages.format_uri || '${$displayName} is not a valid URI.'
);
// pattern
ValidationRules
.customRule(
'pattern',
(val, _obj, pattern) => !!val ? (new RegExp(pattern)).test(val) : true,
this.configuration.messages.pattern || '${$displayName} is not correctly formatted.',
(pattern) => ({ pattern })
);
}
开发者ID:jbockle,项目名称:aurelia-json-schema-form,代码行数:75,代码来源:string-rules.ts
示例7: setupValidation
public setupValidation() {
ValidationRules
.ensure('title').required().minLength(3).withMessage('Title must at least be 3 chars long.')
.ensure('description').required().minLength(3).withMessage('Description must at least be 3 chars long.')
.on(this.todo);
}
开发者ID:Jenselme,项目名称:tests-ionic2-and-aurelia-framework7,代码行数:6,代码来源:edit.ts
示例8: configure
export function configure(aurelia: FrameworkConfiguration, configCallback) {
aurelia.container.registerHandler('fs-validator', container => container.get(FSValidationRenderer));
///** Core **/
aurelia.globalResources('./core/fs-viewport');
aurelia.globalResources('./core/fs-page');
///** Components **/
aurelia.globalResources('./components/fs-content');
aurelia.globalResources('./components/fs-list');
aurelia.globalResources('./components/fs-card');
aurelia.globalResources('./components/fs-swiper');
/** Inputs **/
aurelia.globalResources('./inputs/fs-input');
/** Utils **/
aurelia.globalResources('./utils/fs-converters');
ValidationRules
.customRule('phone', (value, obj) => value === null || value === undefined || PhoneLib.isValid(value), '\${$displayName } is not a valid phone number.');
ValidationRules
.customRule('integer', (value, obj, min, max) => value === null || value === undefined || Number.isInteger(value) && value >= (min || Number.MIN_VALUE) && value <= (max || Number.MAX_VALUE),
'\${$displayName} must be an integer value between \${$config.min || "MIN_VALUE"} and \${$config.max || "MAX_VALUE"}.', (min, max) => ({ min, max }));
ValidationRules
.customRule('decimal', (value, obj, min, max) => value === null || value === undefined || Math.floor(value % 1) === 0 && value >= (min || Number.MIN_VALUE) && value <= (max || Number.MAX_VALUE),
'\${$displayName} must be a decimal value between \${$config.min || "MIN_VALUE"} and \${$config.max || "MAX_VALUE"}.', (min, max) => ({ min, max }));
kramed.setOptions({
renderer: new kramed.Renderer(),
gfm: true,
tables: true,
breaks: true,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
var Configure = {
title: (t) => {
FSConstants.App.Title = t;
return Configure;
},
version: (t) => {
FSConstants.App.Version = t;
return Configure;
},
appKey: (t) => {
FSConstants.App.Key = t;
return Configure;
},
apiUrl: (t) => {
FSConstants.Http.BaseUrl = t;
return Configure;
},
apiHeaders: (t) => {
FSConstants.Http.Headers = t;
return Configure;
},
addAuthHeader: (t) => {
FSConstants.Http.AuthorizationHeader = t;
return Configure;
}
}
if (configCallback !== undefined && typeof configCallback === 'function') {
configCallback(Configure);
}
if (Framework7.prototype.device.ios) {
Dom7('link[rel*="stylesheet"][title="ios"]')[0].disabled = false;
}
if (Framework7.prototype.device.android) {
Dom7('link[rel*="stylesheet"][title="android"]')[0].disabled = false;
}
}
开发者ID:sigmaframeworks,项目名称:sigma-ui-frameseven,代码行数:77,代码来源:sigma-ui-frameseven.ts
注:本文中的aurelia-validation.ValidationRules类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论