web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

SSN field

(0) ShareShare
ReportReport
Posted on by

Am I missing it or is there not a field format out of the box for SSN ???  

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    Hi Debra,

    there isn't an OOB field format for SSN. If you need to do a check validation (number of digits for example) you need to write some JavaScript attached to the OnChange event of the field designed to store the SSN

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    Guido is right, there is no such type available in CRM. However you can use regular expression to validate the data in that field using javascript.

  • Cyclefitness Profile Picture
    on at

    thank you guys.  where do I go to submit enhancement requests?

  • Guido Preite Profile Picture
    54,086 Moderator on at

    Hi Debra,

    normally you can submit the feedback to Microsoft using Connect.

    here a tutorial www.crmanswers.net/.../how-to-use-microsoft-connect-site.html

    but in this specific case (the SSN check) I suggest to don't submit the feedback, because probably it will be closed (it's an easy requirement and can be implemented using JavaScript)

    for example a code can be:

    // code from stackoverflow.com/.../2191473

    // validate social security number with ssn parameter as string

    function validateSSN(ssn) {

       var area = parseInt(ssn.substring(0, 3));

       return (

           ssn.length === 9 &&

           ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/) &&

           area !== 666 &&

           area < 900 &&

           ssn !== '078051120' &&

           ssn !== '219099999'

       );

    }

    function ssnOnChange() {

    var ssn = Xrm.Page.getAttribute("ssnfieldname").getValue();

    if (ssn != null) {

       var isValid = validateSSN(ssn);

       if (isValid == false) {

           Xrm.Page.getAttribute("ssnfieldname").setValue(null);

           alert("SSN NOT VALID");

       }

    }

    }

  • Community Member Profile Picture
    on at

    Hi, I modified Guido's code to format the number depending on what was selected from an option set.  Our ID field also allows a temporary number, so I removed the extra validations for the ID number.

    function formatSSN(context, OptionSetParameter) {

      var SSN = context.getEventSource();

       var idtype = " ";

       var option = Xrm.Page.getAttribute(OptionSetParameter).getSelectedOption();

       //alert("OptionSet Test: " + option.text);

    if (option != null)

    {

          idtype = option.text;

      // alert("Value from Exeuction " + SSN.getValue() + " OptionSetParameter " + option.text);

       // Verify that the field is valid

       if (typeof (SSN) != "undefined" && SSN != null) {

           if (SSN.getValue() != null && idtype != "Green Card") {

               // Remove any special characters

               var sTmp = SSN.getValue().replace(/[^0-9,A-Z,a-z]/g, "");

               var isValid = validateSSN(sTmp);

      if (isValid == false) {

          SSN.setValue(null);

          DisplayNotification("Invalid Tax ID.  Please ensure length is 9 and re-enter ID .", "ERROR", "!");    

      }

      else {

                // format the translated number

               switch (idtype) {

                   case "TIN":

                       SSN.setValue(sTmp.substr(0, 2) + "-" + sTmp.substr(2, 7));

                       break;

                   case "Social Security":

                   case "SSN":

                       SSN.setValue(sTmp.substr(0, 3) + "-" + sTmp.substr(3, 2) + "-" + sTmp.substr(5,4));

                       break;

                   default:

                           // Remove any special characters

                          sTmp = sTmp.replace(/[^0-9,A-Z,a-z]/g, "");

                          SSN.setValue(sTmp);                      

                          break;

             }

          }

           }

    }

       }

    else

    {alert("Please select an ID type.")}

    }

    function validateSSN(sTmp) {

      var area = parseInt(sTmp.substring(0, 3));

        return (

          sTmp.length === 9 &&

          sTmp.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/)    );

    }

  • Suggested answer
    Ryan S Newcomb Profile Picture
    37 on at

    Instead of JavaScript, you can also adjust the control on the form.  On the form designer, open the field properties->Control tab. Add the "Input Mask" control and configure the Mask property to be bound to a static value where you define the format, e.g. 000-00-0000.  This requires the user the enter data according to the format you define, and it doesn't require JavaScript or any coding.

    2019_2D00_06_2D00_14-10_5F00_27_5F00_32_2D00_Contact.png

    What the field will look like when the mask is applied:

    2019_2D00_06_2D00_14-10_5F00_25_5F00_18_2D00_Contact.png

    What the field will look like when a user enters data incorrectly per the format you defined.  In this example, not all of the required digits were added and so the input mask doesn't allow the value to save. 

    2019_2D00_06_2D00_14-10_5F00_30_5F00_56_2D00_Contact.png

    What the field will look like when a user enters data correctly per the format you defined:

    2019_2D00_06_2D00_14-10_5F00_27_5F00_32_2D00_Contact.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans