解决与正则表达式相关的查询

时间:2011-05-23 06:31:21

标签: asp.net

我有2个文本框;在一个文本框上我有两个验证

1)输入值和所需的字段验证 2)正则表达式,取Employee_id binary(7),其格式为- B-____,即B-将固定在它之前的5位数,这将是什么格式?

另一个文本框有电话号码。什么是印度标准电话号码的格式?

这些

的正则表达式是什么
<table>
 <td class="style35">
                &nbsp;</td>
            <td class="style32">
                <asp:Label ID="Lbl_Emp_Code" runat="server" Font-Bold="True" 
                    Text="Employee Code"></asp:Label>
            </td>
            <td class="style34">
                <asp:TextBox ID="Txt_Code" runat="server"></asp:TextBox>
            </td>
            <td class="style31">
                <asp:RequiredFieldValidator ID="Rfv_code" runat="server" 
                    ControlToValidate="Txt_Code" ErrorMessage="Please Enter Employee Code">*</asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="R_exp_v_Code" runat="server" 
                    ControlToValidate="Txt_Code" 
                    ErrorMessage="Please Enter correct Format of Employee Code">*</asp:RegularExpressionValidator>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style35">
                &nbsp;</td>
            <td class="style32">
                <asp:Label ID="Lbl_Emp_Name" runat="server" Font-Bold="True" 
                    Text="Employee Name"></asp:Label>
            </td>
            <td class="style34">
                <asp:TextBox ID="Txt_Name" runat="server"></asp:TextBox>
            </td>
            <td class="style31">
                <asp:RequiredFieldValidator ID="Rfv_name" runat="server" 
                    ControlToValidate="Txt_Name" ErrorMessage="Please Enter Employee Name">*</asp:RequiredFieldValidator>
            </td>
            <td>
                &nbsp;</td>

</table>

2 个答案:

答案 0 :(得分:1)

好的,如果我理解你的问题,你就有2个文本框

1- EmployeeID(格式为B-[5 digit number]

2- EmployeeNumber(印度电话号码[不确定您是指手机号码还是固定电话号码])

所以这是基于我理解的答案

您可以使用ValidationExpression标记的<asp:RegularExpressionValidator>属性来指定正则表达式。

对于您的EmployeeID(B-[5 digit number]),您可以尝试^[B-]\d{5}作为您的注册表。

对于您的EmployeeNumber,您可以尝试\d{8}获取固定电话号码,\d{10}获取手机号码。

希望它有所帮助。

PS:虽然我个人觉得使用Regex理解/写作要简单得多。

答案 1 :(得分:0)

员工代码B为固定且5位数正则表达式为^ [B- | b - ] + [\ d] {5}