Formatting an SSN so user only has to enter the numbers

2 posts, 0 answers
  1. MArkB
    MArkB avatar
    7 posts
    Member since:
    Dec 2012

    Posted 25 Apr 2013 Link to this post

    HI folks,

    I've got myself a RadTextBox where the users are creating new records where one of the values is an SSN. From one of the examples I got the validation to make sure it's in the right format and that's working as expected. I'd like to add to the behavior so that it doesn't require the user to enter the dashes. In a best case scenario, the user could enter the dashes, or not, and the system will still accept the value.

    This is whut I've got now:
    <telerik:RadTextBox ID="txtSSN" runat="server" EmptyMessage="Enter valid SSN..." Width="250px"></telerik:RadTextBox>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ValidationGroup="AddPatient" ErrorMessage="* Required Field" ControlToValidate="txtSSN" /><br />    
              <asp:RegularExpressionValidator id="ssnValidator" runat="server" Display="Dynamic" ErrorMessage="Invalid SSN format"
              ValidationExpression="\d{3}-\d{2}-\d{4}" ControlToValidate="txtSSN">

    Thanks for the help.

    MArk B.
  2. Vasil
    Vasil avatar
    1604 posts

    Posted 30 Apr 2013 Link to this post

    Hello Mark,

    We don't have control, that to provide you masked with optional symbols. The closes to your requirements is RadMaskedTextBox that will autotype the Hyphen-minus automatically. Here is an example:

    <telerik:RadMaskedTextBox ID="txtSSN" runat="server" Mask="###-##-####"></telerik:RadMaskedTextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" Text="* Required Field" ControlToValidate="txtSSN" /><br />
    <asp:RegularExpressionValidator ID="ssnValidator" runat="server" Text="Invalid SSN format"
        ValidationExpression="\d{3}-\d{2}-\d{4}" ControlToValidate="txtSSN">

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top