1

I have jquery function as validationtype its working fine

<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");

but my req is i need to pass regex at runtime to this function

how to achieve this, i tried like...

ValidationType = "mytest";

ValidationParameters.Add("newregex", strrew);

its reflecting in html like....

input class="text-box single-line" data-val="true" data-val-mytest="The ContactPersonName field is Required." data-val-mytest-newregex="/^[a-zA-Z0-9]{50,100}$/" id="Desc" name="Desc" type="text" value=""

David Fox
  • 10,603
  • 9
  • 50
  • 80
vijay
  • 33
  • 5

2 Answers2

0

You might find the following answer useful.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • var myPattern = /^(\+?((([0-9]+(\.)?)|([0-9]*\.[0-9]+))([eE][+-]?[0-9]+)?))$/; this is working var myPattern = param1; this is not working – vijay Jul 11 '11 at 13:05
0

Not quite what your looking for, but for ease you could use the remote validation attribute.

RubbleFord
  • 7,456
  • 9
  • 50
  • 80