.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.

        <div>
            <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" />
        </div>

Open in new window

Larry Bristersr. DeveloperAsked:
Who is Participating?
 
Kyle AbrahamsSenior .Net DeveloperCommented:
from:
https://forums.asp.net/t/1114240.aspx?envoke+a+javascript+function+if+regularexpressionvalidator+is+true+or+false



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;
    }
</script>

Open in new window

0
 
Larry Bristersr. DeveloperAuthor Commented:
Thanks
0
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.