Home > ASP.Net > RegularExpressionValidator change color of textbox

RegularExpressionValidator change color of textbox


Hi

try this example

<script language="javascript" type="text/javascript">
    function check1(source, args)
        {
            var txt = document.getElementById('<%= txt_Name.ClientID %>');
            if(args.Value.length == 0)
            {
                txt.style.background = '#f1f4fb';
                args.IsValid = false;
            }
            else
            {
                txt.style.background = '#ffffff';
                args.IsValid = true;
            }
        }
       
       

    </script>

<asp:TextBox ID="txt_Name" runat="server" BorderStyle="Dotted" BorderColor="#C0C0FF" Width="204px"></asp:TextBox>&nbsp;<br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_Name"
                            ErrorMessage="Your name is required." Font-Size="9pt"></asp:RequiredFieldValidator>
                            <asp:CustomValidator ID="CustomValidator1" runat="server"
                                ClientValidationFunction="check1" ControlToValidate="txt_Name" ValidateEmptyText='true'
                                ErrorMessage="CustomValidator" Font-Size="9pt" Display="None"></asp:CustomValidator>

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: