Validating an Empty textbox field with Customvalidator

Asked

Viewed 531 times

0

I need to validate a Textbox field, for when it is empty paint to embroider indicating that there is some error with the field, I am using the customValidador but it is not working.

The code of Function.

function ValidatxtECFNrSerie(src, args) {
        if (args.Value.length > 1) { 
            args.IsValid = true;
        }
        else { 
            args.IsValid = false;
        }

    }

and field code to validate.

<asp:TextBox ID="txtECFNrSerie" runat="server" MaxLength="15" Width="150px"></asp:TextBox>
<asp:CustomValidator runat="server" ID="CustomValidator1" ClientValidationFunction="ValidatxtECFNrSerie" ErrorMessage=" * "   ValidationGroup="vgValidarCampo" Display="Dynamic" ControlToValidate="txtECFNrSerie"></asp:CustomValidator>

How do I validate an empty field with Customvalidator ?

1 answer

0


Hello,

Follows the code

function ValidatxtECFNrSerie(src, args) {
        if (string.IsNullOrEmpty(args.Value)) { 
            args.IsValid = false;
        }
        else { 
            args.IsValid = true;
        }

    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.