在运行时在mvc中将值传递给Jquery验证?

时间:2011-07-11 11:48:25

标签: jquery asp.net-mvc-3

我有jquery函数作为validationtype,工作正常

<script type="text/javascript">

jQuery.validator.addMethod("mytest", function (value, element, param) {
    var emailPattern = /^[0-9]+$/;
    return emailPattern.test(value);
});

jQuery.validator.unobtrusive.adapters.addBool("mytest");

但我的需要是我需要在运行时将正则表达式传递给此函数

如何实现这一点,我试着......

ValidationType = "mytest";

ValidationParameters.Add(“newregex”,strrew);

它反映在html中......

input class =“text-box single-line”data-val =“true”data-val-mytest =“ContactPersonName字段是必需的。”数据-VAL-mytest的-newregex = “/ ^ [A-ZA-Z0-9] {50100} $ /”  id =“Desc”name =“Desc”type =“text”value =“”

2 个答案:

答案 0 :(得分:0)

您可能会发现following answer有用。

答案 1 :(得分:0)

不是您想要的,但为了方便您可以使用远程验证属性。