【问题标题】:Aurelia Validation MatchesAurelia 验证匹配
【发布时间】:2016-03-14 15:56:03
【问题描述】:

我想弄清楚我将如何做一个startsWith?这是一个自定义元素,它需要验证字符串是否以“\”开头

<template>
    <input disabled.bind="readonly" type="text" class="form-control" value.bind="value">
</template>

import {customElement, bindable, inject, bindingMode} from 'aurelia-framework';
import {activationStrategy} from 'aurelia-router';
import $ from 'jquery';
import {Validation} from 'aurelia-validation';



@customElement('url')
@bindable({name: 'value', attribute: 'value', defaultValue: '', defaultBindingMode: bindingMode.twoWay})
@bindable({name: 'readonly', attribute: 'disabled', defaultValue: false, defaultBindingMode: bindingMode.oneWay})
@inject(Element, Validation)
export class Url {
    constructor(element, validation) {
        this.element = element;

        this.validation = validation.on(this)
                    .ensure(this.element)
                    .isNotEmpty()
                    .containsNoSpaces()
                    .matches('/^[\].*/');
    }

    bind(){
        $('.input', this.element).val(this.value);

        if(this.readonly){
            $('.input', this.element).attr('readonly', 'readonly');
        }
    }
}

我查看了http://aurelia.io/validation/#/logical-operators,我认为我做得对,但它会引发错误:内部错误:TypeError: path.split is not a function

【问题讨论】:

标签: aurelia


【解决方案1】:
  1. 函数ensure()接受验证字段的名称,而不是元素
  2. 无需用引号括起您的正则表达式

应该是这样的

this.validation = validation.on(this)
                         .ensure('value')   
                         .isNotEmpty()
                         .containsNoSpaces()
                         .matches(/^\\.*$/);

【讨论】:

    猜你喜欢
    • 2017-12-26
    • 2018-09-14
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多