MisterSnrub 0 Newbie Poster

My form has a RegularExpressionValidator that validates user input in a textbox, lik so:

<asp:TextBox ID="taSSN" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revSSN" runat="server" 
    ControlToValidate="taSSN" 
    ValidationExpression="^\d{3}-\d{2}-\d{4}$">
    Invalid! Remember, you MUST type in the dashes!!
</asp:RegularExpressionValidator>

Suppose that that the regular expression I want to validate is the standard U.S. Social Security Number which is the following: ^\d{3}-\d{2}-\d{4}$ Now, in order for user input to be valid, it MUST have the two dashes. Therefore, 123-45-6789 would be valid, but 123456789 would not. Well, if the user types in a nine-digit number (in other words, if the following regular expression is valid: ^\d{9}$ ), then it's pretty obvious that this is a valid SSN and I want to have dashes get automatically inserted into the textbox before validation of the main regular expression begins. I don't want the user thinking "Hmmm... I don't know if I need the dashes or not." Just put them there if the user didn't type them in, then try to validate. How do I do this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.