.Net Validator Control

The following code works but I would like to highlight the text in the TextBox if the validator is invoked because a number is entered.

            <asp:TextBox ID="txtTest" runat="server" Width="200px"></asp:TextBox><br />
            <asp:RegularExpressionValidator ValidationExpression="^[a-zA-Z\- ]{0,50}" ID="val1" runat="server" SetFocusOnError="true" ControlToValidate="txtTest" ErrorMessage="Alpha Only!"></asp:RegularExpressionValidator>
            <br />
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" />

Open in new window

Larry Bristersr. DeveloperAsked:
Who is Participating?
Kyle AbrahamsSenior .Net DeveloperCommented:

use OnPropertyChange to fire a javascript function:
onpropertychange=" ValidateInput()"

 <script type="text/javascript">
    function ValidateInput() {
    var rev = document.getElementById('val1');
        if (rev.style.visibility != 'hidden')
            document.getElementById('<%= txtTest.ClientID %>').style.borderColor = "red";
            return false;
        return true;

Open in new window

Larry Bristersr. DeveloperAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.