I have 2 textbox; on one textbox I have two validations
1) required field validation for entering value and
2) regular expression which take Employee_id binary(7), its format is - B-____ i.e B- will be fix 5 digits preceding it and what would be the format of this?
Another textbox has phone no. What would be the format of indian standard phone no.?
What will be the regular expression for these
<table>
<td class="style35">
</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>
</td>
</tr>
<tr>
<td class="style35">
</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>
</td>
</table>
Ok, if I have understood your question right, you have 2 textboxes
1- EmployeeID (has the format
B-[5 digit number])2- EmployeeNumber (Indian tel. no. [not sure if you mean a cell phone number or a fixed line number])
so here’s the answer based on my understanding
You can use the
ValidationExpressionproperty of the<asp:RegularExpressionValidator>tag to specify you regular expression.For your EmployeeID (
B-[5 digit number]) you can try^[B-]\d{5}as your regEx.and for your EmployeeNumber you can try
\d{8}for fixed-line number and\d{10}for cell phone numbers.hope it helps.
PS: although I personally feel it’s a lot simpler to understand/write using
Regex.