How to validate text box?
<pre><code>public bool ValidateText(String strName)
{
    try
    {
        // declaring string variable here
        String strpattern;
        // regex pattern setting 
        strpattern = @"^[a-zA-Z][a-zA-Z0-9']{20}$";
        // checking for matching with given string here
        Regex regex = new Regex(strpattern);
        // returns status here
        return regex.IsMatch(strName);
    }
    catch (Exception ex)
    {
        return false;
    }
}
</code></pre>

<p>when i try insert name like q''''''''''''''''' it is returning string value instead of boolean value . plz , let me know wer im going wrong in this particular function ???</p>

<p>I need to validate the text inside the TextBox. In other words the Text inside the TextBox if not matching with the given <code>pattern</code> then it should be converted to matching string. This should be checked for every user entered character or if the user pasted collection of characters.</p>
