Home > Archive > ASP .NET > December 2006 > RegularExpressionValidator
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RegularExpressionValidator
|
|
| simonZ 2006-12-21, 8:07 am |
| I have RegularExpressionValidator which validate one text box.
When my text box is validated on client I would like to do something else.
Is there some client event of RegularExpressionValidator?
Something like after validate?
something like:
<script language="javaScript">
function afterValidate(arg){
if (arg.isValid )
{
//do something
}
}
</script>
regards,S
| |
| Milosz Skalecki 2006-12-21, 8:07 am |
| Hi Simon,
Client side validation API:
http://msdn.microsoft.com/library/d...spplusvalid.asp
There are many ways to accomplish this task:
- you can force validators to run their validation methods by calling
ValidatorValidate(val)
- instead of using reqularexpressionvalidator, use customvalidator in
conjunction with clinetfunctionname property, and Regex DOM object (it's
easy to incorporate the same functionality as regularexpressionvalidator)
example :
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="MyValidationFunction" ControlToValidate="txt"
ErrorMessage="try again...."
OnServerValidate="CustomValidator1_ServerValidate"/>
<script runat="server">
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = System.Text.RegularExpressions.Regex.IsMatch(args.Value,
"[0-9]+");
}
</script>
<script language="javascript">
function MyValidationFunction(src, e)
{
e.IsValid = e.Value.match('[0-9]+');
// do something here...
}
</script>
--
Milosz Skalecki
MCAD
"simonZ" wrote:
> I have RegularExpressionValidator which validate one text box.
> When my text box is validated on client I would like to do something else.
>
> Is there some client event of RegularExpressionValidator?
>
> Something like after validate?
>
> something like:
>
> <script language="javaScript">
> function afterValidate(arg){
> if (arg.isValid )
> {
> //do something
> }
> }
> </script>
>
> regards,S
>
>
>
| |
| simonZ 2006-12-21, 7:07 pm |
| Thank you, Milosz
this was exactly what I needed.
Regards,S
"Milosz Skalecki" <mily242@REMOVEITwp.pl> wrote in message
news:6DFEC58C-C063-468F-9B88-690337B7E7FB@microsoft.com...[color=darkred]
> Hi Simon,
>
> Client side validation API:
> http://msdn.microsoft.com/library/d...spplusvalid.asp
>
> There are many ways to accomplish this task:
>
> - you can force validators to run their validation methods by calling
> ValidatorValidate(val)
> - instead of using reqularexpressionvalidator, use customvalidator in
> conjunction with clinetfunctionname property, and Regex DOM object (it's
> easy to incorporate the same functionality as regularexpressionvalidator)
>
> example :
>
>
> <asp:CustomValidator ID="CustomValidator1" runat="server"
> ClientValidationFunction="MyValidationFunction" ControlToValidate="txt"
> ErrorMessage="try again...."
> OnServerValidate="CustomValidator1_ServerValidate"/>
>
> <script runat="server">
>
> protected void CustomValidator1_ServerValidate(object source,
> ServerValidateEventArgs args)
> {
> args.IsValid = System.Text.RegularExpressions.Regex.IsMatch(args.Value,
> "[0-9]+");
> }
>
> </script>
>
> <script language="javascript">
> function MyValidationFunction(src, e)
> {
> e.IsValid = e.Value.match('[0-9]+');
>
> // do something here...
> }
> </script>
> --
> Milosz Skalecki
> MCAD
>
>
> "simonZ" wrote:
>
| |
| bruce barker 2006-12-21, 7:07 pm |
| note, this article is for version 1. client side validation is simular
for version 2, but there are implementation differences (javascript
variables instead of spans, for example).
-- bruce (sqlwork.com)
Milosz Skalecki wrote:
> Hi Simon,
>
> Client side validation API:
> http://msdn.microsoft.com/library/d...spplusvalid.asp
>
> There are many ways to accomplish this task:
>
> - you can force validators to run their validation methods by calling
> ValidatorValidate(val)
> - instead of using reqularexpressionvalidator, use customvalidator in
> conjunction with clinetfunctionname property, and Regex DOM object (it's
> easy to incorporate the same functionality as regularexpressionvalidator)
>
> example :
>
>
> <asp:CustomValidator ID="CustomValidator1" runat="server"
> ClientValidationFunction="MyValidationFunction" ControlToValidate="txt"
> ErrorMessage="try again...."
> OnServerValidate="CustomValidator1_ServerValidate"/>
>
> <script runat="server">
>
> protected void CustomValidator1_ServerValidate(object source,
> ServerValidateEventArgs args)
> {
> args.IsValid = System.Text.RegularExpressions.Regex.IsMatch(args.Value,
> "[0-9]+");
> }
>
> </script>
>
> <script language="javascript">
> function MyValidationFunction(src, e)
> {
> e.IsValid = e.Value.match('[0-9]+');
>
> // do something here...
> }
> </script>
|
|
|
|
|