How to fix length of string in textbox using regular expression validator in asp.net c#

Many time we want to save the username value with specify length of string  so I am trying to solve this problem with regular  expression validator because we need only this expression value  :-

ValidationExpression="^[\s\S]{6,12}$"

For more understating I am giving this example :-

Sources code :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">

        .style2
        {
            width: 100%;

        }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style2">
            <tr>
                <td align="right" class="style3">
                    User Name</td>
                <td align="left" colspan="2" width="800">
                    <asp:TextBox ID="txtusername" runat="server" Width="180px"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="revusername" runat="server"
                        ControlToValidate="txtusername" Display="Dynamic"
                        ErrorMessage="Please choose username length between 6-12 characters"
                        ForeColor="Red" Style="font-size: small"
                        ValidationExpression="^[\s\S]{6,12}$"></asp:RegularExpressionValidator>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


Out-put




How to fix length of string in textbox using regular expression validator in asp.net c# How to fix length of string in textbox using regular expression validator in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 6:03:00 PM Rating: 5

No comments:

Powered by Blogger.