自定义属性在razor mvc中不起作用

时间:2017-06-09 09:46:11

标签: c# asp.net-mvc razor

我想验证每个输入,如下所示是js中的代码

countDown() {
  var n = this.timer
  if (!this.counter) {
    this.counter = true;
  } else if (n > 0) {
    n = n - 1
    this.timer = n
    this.message2 = "You have " + n + "seconds left."
  } else {
    clearInterval(this.interval);
    this.counter = false
    this.message2 = "Your time is up!"
  }
},

它与文本框完美配合

var inputs = document.querySelectorAll('input[data-filter]');

for (var i = 0; i < inputs.length; i++) {

    var input = inputs[i];
    var state = {
        value: input.value,
        start: input.selectionStart,
        end: input.selectionEnd,
        pattern: RegExp('^' + input.dataset.filter + '$')
    };

    input.addEventListener('input', function (event) {
        if (state.pattern.test(input.value)) {
            state.value = input.value;
        } else {
            input.value = state.value;
            input.setSelectionRange(state.start, state.end);
        }
    });

    input.addEventListener('keydown', function (event) {
        state.start = input.selectionStart;
        state.end = input.selectionEnd;
    });
}

原始正则表达式 @Html.TextBoxFor(m=>m.Telephone, new { id="phone", data_filter="\\+?(?:\\d\\s?){0,13}"}) 转义反斜杠,因为它提供了错误

^\+?(?:\d\s?){11,13}$

它不适用于razor。问题是什么?

0 个答案:

没有答案