Clearing Text In Regular Expression Validator RRS feed

  • Question

  • User-404462136 posted
    Dear all, How can I clear the text property of a Regular Expression Validator (or reset the controlto default state) from a client side button click ? I know I can use the My.Validator.InnerHTML property from a javascript file, but once I clear it using this property, the control stops working !!! Any help will be much appreciated. Thank you. Nandan
    Friday, May 7, 2004 12:02 PM

All replies

  • User1806792307 posted
    Validators keep their error message in the innerHTML full time. They simply show and hide themselves to work with the error message. To hide a validator, retrieve the object associated with its ClientID and set its visibility to 'hidden'. var vVal = document.all['clientid of validator']; vVal.style.visibility = "hidden"; vVal.style.display = "none"; // ONLY if you are using Display="Dynamic"
    Friday, May 7, 2004 2:06 PM
  • User-404462136 posted
    Thank you for your help. But doing what you asked me still has the same result. The control stops working after that point onwards, unless I explicitly make it visible through some more javascript code. All I need to do though is, just reset the control to its default setting... So, its still ready to validate anything being entered in the text box. Your help is appreciated. Nandan
    Friday, May 7, 2004 2:24 PM
  • User1806792307 posted
    Can you clarify how it stops working? I have been interpreting your message this way: You are trying to use the <form onreset= > event to clear validators to their hidden state. My answer gives you code that hides the validator without changing its innerHTML. When you changed the innerHTML, the validator would still show and hide the tag containing it but have nothing inside the tag to show. It appears off. FYI: If the reset button is the problem, here's an alternative solution to developing this custom code. The inability to clear validators upon reset is one of the many limitations of Microsoft's validators. I wrote a replacement to Microsoft's validators that overcomes its limitations including the ability to reset the validators to the same condition they were as the page first appeared. You can learn more about Professional Validation And More here and the limitations of Microsoft's validators here.
    Friday, May 7, 2004 3:12 PM
  • User371668647 posted
    If you call Page_Validate and the error has been fixed, then the error message should get cleared. Is this not what you are seeing?
    Monday, May 10, 2004 7:05 AM
  • User-404462136 posted
    Dear Peter and Stiletto, Thank you for your replies... What is happening with my page is this: I have: A TextBox A "Clear" Button A Regular Expression Validator (Which lets the textbox accepts only Numbers) Everything works according to my expectations... Whenever a non-valid input is typed, an error message is correctly displayed... Now the problem arises when I want to clear the Input in the textbox and also the Error Message when the user presses the "clear" button. If I use InnerHTML property or the Visibility property explicitly to clear or hide the error message, the error message should be explicitly set or control needs to be explicitly displayed again at some later point, for it to continue working in a Normal fashion. All I need to know is this, if there is a way I can revert the control's state to the state it was in when the page was first loaded, then the error message should automatically get cleared with it... correct ? Or if there is any other simple way of clearing the error message WITHOUT tampering with the normal functioning of the control (like resetting the control to its default state)... Thank you for your help.... Best regards, Nandan
    Monday, May 10, 2004 9:16 AM
  • User1806792307 posted
    You cannot modify the field to its original state and get the validator back to its hidden state. Validators only update on the onchange event of a field, which only fires if the user edits the field, and when the Page_Validate() function is run on submit. You haven't clearly said that your Clear button is a <input type='reset'> and you are using the <form onreset= > event or using the onclick event of an <input type='button'> with some script that you wrote to clear fields. Either way, if the fields are cleared, you can run the Page_Validate() function after you reset the fields. The side effect is if you have a RequiredFieldValidator, it will see any blank field and show its error message. As I said, this is a basic limitation of Microsoft's validators and I've offered you a commercial solution that handles this correctly. It's your choice whether you spend time developing hacks and lots of custom code each time you run into one of these limitations.
    Monday, May 10, 2004 1:05 PM
  • User2143164999 posted



    I think this situation come across many programmers, I guess the solution can be obtained by using the following in javascript 

    document.getElementById("regurlarexpressionID").style.visibility = "hidden";


    Tuesday, March 3, 2009 12:50 AM
  • User-1484203585 posted

    If I understand this issue to be the same as mine, then the problem is that once the regular expression message has been suppressed on the press of a Reset button by changing its style to “hidden” or suchlike in a javascript function, that it stays hidden on subsequent presses of the Send button, i.e. the validation messages are not seen again, even though validation occurs.

    I solved my requirements by implementing the suggestion of William F. Robertson, Jr. As per thread :-


    quote <My "reset" button, just re-requests the page. Would this work for you?

    <input type="button" onclick="javascript: location.href = location.href;"
    value="reset" />

    I found it easier to do this, rather than try to clear textboxes, reset drop
    down, validators, etc.> end quote

    Just thought I'd share this. 

            function btnReset_onclick() {

    //            document.getElementById("RFVEmail").style.visibility = "hidden";

    //            document.getElementById("RegularExpressionValidator1").style.visibility = "hidden";

    //            document.getElementById("RFVMessage").style.visibility = "hidden";

    //            document.getElementById("RFVEmail").style.display = "none";

    //            document.getElementById("RegularExpressionValidator1").style.display = "none";

    //            document.getElementById("RFVMessage").style.display = "none";

    //            document.getElementById("RFVEmail").style.enabled = "false";

    //            document.getElementById("RegularExpressionValidator1").style.enabled = "false";

    //            document.getElementById("RFVMessage").style.enabled = "false";



    <input id="btnReset" type="reset" value="reset" onclick="javascript: location.href = location.href;" />

        <!--input id="btnReset" type="reset" value="reset" onclick="return btnReset_onclick()" /-->

    Friday, June 3, 2011 2:22 PM