Validating a SSN that uses 3 textBox controls

gardnercopper

New Member
Instead of using one textbox control for SSN, I am using three seperate boxes. First textbox for the first three digits of ssn, second textbox for middle two digits, etc ... I want to be able to combine all three textbox values into one string and validate that value. The value is required and I want to make sure the value is 9 digits long. I currently have the following code, but as you can see it does no validate how I want it to. It validate each textbox control seperately.<BR><BR><TR><BR> <TD><asp:label id="SSNLabel" runat="server" Font-Size="Smaller">Social Security Number:</asp:label></TD><BR> <TD><asp:textbox id="SSN1" runat="server" MaxLength="3" Width="35px"></asp:textbox>-<asp:textbox id="SSN2" runat="server" MaxLength="2" Width="20px"></asp:textbox>-<asp:textbox id="SSN3" runat="server" MaxLength="4" Width="40px"></asp:textbox><BR> </TD><BR> <TD><BR> <asp:RequiredFieldValidator id="SSN1Required" runat="server" ControlToValidate="SSN1" Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator><BR> <asp:RequiredFieldValidator id="SSN2Required" runat="server" ControlToValidate="SSN2" Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator><BR> <asp:RequiredFieldValidator id="SSN3Required" runat="server" ControlToValidate="SSN3" Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator><BR> <asp:RegularExpressionValidator id="SSN1Regular" runat="server" ValidationExpression="d{3}" ControlToValidate="SSN1" Display="Dynamic" ErrorMessage="Invalid Entry"></asp:RegularExpressionValidator><BR> <asp:RegularExpressionValidator id="SSN2Regular" runat="server" ValidationExpression="d{2}" ControlToValidate="SSN2" Display="Dynamic" ErrorMessage="Invalid Entry"></asp:RegularExpressionValidator><BR> <asp:RegularExpressionValidator id="SSN3Regular" runat="server" ValidationExpression="d{4}" ControlToValidate="SSN3" Display="Dynamic" ErrorMessage="Invalid Entry"></asp:RegularExpressionValidator></TD><BR> </TR><BR><BR>Thanks in advance ....I don't think you can have one validation control setup to validate multiple Web controls - they were designed to have a 1:1 correspondence with Web controls.<BR><BR>What you could do is when the form is submitted, use server-side code to combine the results of the three textboxes and then write a few lines of code to ensure it's 9 digits (i.e., Regex.Test(combinedString, "d{9}")). Alternatively you could implement this all as a custom Web control....
 
Back
Top