Hello John,
I've done some research and here are some script code snippet that
works(actually it is picked modified from the asp.net regular expression
validator's client output code). Here is the script function and the html
elements on the test page:
=========================
.............................
function validate()
{
alert("validation started....");
var input = document.getElementById("txtInput").value;
var rx = new RegExp(document.getElementById("txtPattern").value);
var matches = rx.exec(input);
var result = (matches != null && input == matches[0]);
alert("result: " + result);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
Validation Pattern: <textarea name="txtPattern" id="txtPattern"
value="^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$" rows="3" cols="30" ></textarea>
<br />Input Data: <input type="text" name="txtInput" id="txtInput" />
<input type="button" value="do validation"
onclick="javascript:validate();" />
<br /><br /><br />
<hr /><br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
....................
======================================
I explicitly create a RegExp jscript object and assign the regular
expression(Pattern) into its constructor. and call its "exec" method
against the text (you want to validate) will return a matches list, you can
check whether it is null or whether the first item is your input text to
determine whether the vaildation succeed.
This works with some test regular expressions. However, for the patter
regex you provided, I always get validation failure, I'm not sure whether
there is any typo in the expression or if i haven't input the correct
datetime value
Anyway, hope this helps some.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.