locked
How we can allow masked edit in textbox RRS feed

  • Question

  • Hi All,

    Please any one can know me how we can allow masked edit in textbox. e.g. Phone, FAX, SSN No etc..

    Please know me how we can accomplish this.

    Thanks alot in advance Smile
    Wednesday, October 15, 2008 9:52 AM

Answers

  • No problem.

     

    Be aware that I am not an expert (by any means) with Java Script.  I pulled the following code from the 'Working with Microsoft Dynamics CRM 3.0', published by Microsoft Press, and authored by co-founders/principals (Mike Snyder and Jim Steger) of Sonoma Partners (CRM Partner).

     

    It works for Phone Number fields (considering US Domestic formatting - which we set as (___) ___-____).  I altered it to some degree, but it has been working well, except for when I may clear a phone and tab out of the field (it prompts an error - but not a show stopper).  I am sure that with some additional tweaking (debugging), the error could be resolved.

     

    I am sure you could use the same method to format a Tax ID (SSNu or FEDId) field.

     

    Here is the Script I have applied in all areas where a Phone is used.  Given that this is pretty much standard throughout our deployment, I believe that it could be stream-lined by building/deploying a plug-in (for 4.0), or through an assembly (3.0).  These methods are described in the same book I acknowledged in this reply.

     

    Incidentally, the same set of code worked well in our CRM 4.0 Dev/Test deployment (since we are on the cusps of upgrading from 3.0 to 4.0).

     

    // Attempt to auto-format basic United States phone numbers. This method supports
    // 7 and 10 digit numbers. Example: 4105551212 and 5551234

     
    // Get the field that fired the event
    var oField = event.srcElement;
     
    // If the field exists and is not null
    if (typeof(oField) != "undefined" && oField != null)
    {
      // Remove any non-numeric characters
      var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
     
      // If the number is a length we expect and support, format the number
      switch (sTmp.length)
        {
            case 7:
                oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4);
                break;
            case 10:
                oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
                break;
        }
    }

     

    // End of Script

     

    The only thing I would like to add is some scripting to bypass the alteration (adding the masking), if formatting has already been added; or to validate what is entered to validate if it is similar to domestic and then prompt that it needs to be altered to standard phone masking, giving user option to decline if they already know it is NOT a domestic number and the formatting is desired for what is entered.  Possiby some additional case statements (or If/Then logic) and comparison of what is in the field to some likely candidates that are Close, but not exact (such as (___)___-____ instead of (___) ___-____).  I have no problem working this out through SQL, but still short on expertise on effectively coding this in java script.

     

    TB

    Thursday, October 16, 2008 1:23 PM
  • Thanks alot my freind.

    Here is the more corrected version

    http://blogs.msdn.com/midatlanticcrm/archive/2005/11/07/489940.aspx

    Thanks.
    Friday, October 17, 2008 2:11 AM

All replies

  •  

    Possibly you already know this, but you can use a client-side script to take the values entered (without formatting/masking), and then apply a mask to it (through the OnChange event).

     

    If you are trying to expose a masking format in the field while the user is typing in the values, then I am not sure what method would be used, but I would like to find out.

     

    TB

    Wednesday, October 15, 2008 4:55 PM
  • Hi,

    Thanks for your reply.

    Can you please send me client-side javascript to apply mask on OnChange event.


    Thursday, October 16, 2008 2:35 AM
  • No problem.

     

    Be aware that I am not an expert (by any means) with Java Script.  I pulled the following code from the 'Working with Microsoft Dynamics CRM 3.0', published by Microsoft Press, and authored by co-founders/principals (Mike Snyder and Jim Steger) of Sonoma Partners (CRM Partner).

     

    It works for Phone Number fields (considering US Domestic formatting - which we set as (___) ___-____).  I altered it to some degree, but it has been working well, except for when I may clear a phone and tab out of the field (it prompts an error - but not a show stopper).  I am sure that with some additional tweaking (debugging), the error could be resolved.

     

    I am sure you could use the same method to format a Tax ID (SSNu or FEDId) field.

     

    Here is the Script I have applied in all areas where a Phone is used.  Given that this is pretty much standard throughout our deployment, I believe that it could be stream-lined by building/deploying a plug-in (for 4.0), or through an assembly (3.0).  These methods are described in the same book I acknowledged in this reply.

     

    Incidentally, the same set of code worked well in our CRM 4.0 Dev/Test deployment (since we are on the cusps of upgrading from 3.0 to 4.0).

     

    // Attempt to auto-format basic United States phone numbers. This method supports
    // 7 and 10 digit numbers. Example: 4105551212 and 5551234

     
    // Get the field that fired the event
    var oField = event.srcElement;
     
    // If the field exists and is not null
    if (typeof(oField) != "undefined" && oField != null)
    {
      // Remove any non-numeric characters
      var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
     
      // If the number is a length we expect and support, format the number
      switch (sTmp.length)
        {
            case 7:
                oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4);
                break;
            case 10:
                oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
                break;
        }
    }

     

    // End of Script

     

    The only thing I would like to add is some scripting to bypass the alteration (adding the masking), if formatting has already been added; or to validate what is entered to validate if it is similar to domestic and then prompt that it needs to be altered to standard phone masking, giving user option to decline if they already know it is NOT a domestic number and the formatting is desired for what is entered.  Possiby some additional case statements (or If/Then logic) and comparison of what is in the field to some likely candidates that are Close, but not exact (such as (___)___-____ instead of (___) ___-____).  I have no problem working this out through SQL, but still short on expertise on effectively coding this in java script.

     

    TB

    Thursday, October 16, 2008 1:23 PM
  • Thanks alot my freind.

    Here is the more corrected version

    http://blogs.msdn.com/midatlanticcrm/archive/2005/11/07/489940.aspx

    Thanks.
    Friday, October 17, 2008 2:11 AM
  • I’ve posted a generic solution for this requirement.

    http://mscrm4ever.blogspot.com/2008/08/creating-crm-field-mask-format.html

     

    Adi

     

    Wednesday, January 14, 2009 7:06 PM