locked
How to allow only numbers in a text field in CRM 2015? RRS feed

  • Question

  • Hi All,

    Can anybody help me achieving the below requirement in a supported way?

    - I have a text field named "Phone" in an entity.

    - Phone should contain only 8 digit and numbers.

    I have gone through some solutions but seems to be an unsupported way. Please help with any solution in a supported way.

    Thanks & Regards,

    Sri

    Thursday, June 11, 2015 8:18 AM

Answers

  • Hi All,

    Used the below script and achieved the requirement.

     

    function ValidateNo(NumStr, String) {
        for (var Idx = 0; Idx < NumStr.length; Idx++) {
            var Char = NumStr.charAt(Idx);
            var Match = false;

            for (var Idx1 = 0; Idx1 < String.length; Idx1++) {
                if (Char == String.charAt(Idx1))
                    Match = true;
            }

            if (!Match)
                return false;
        }
        return true;
    }

    Thanks,

    Sri

     
    • Marked as answer by K_Srinivas Monday, June 22, 2015 1:28 AM
    Monday, June 22, 2015 1:28 AM

All replies

  • Hi Sri,

          You can write a script which enforces regex validation on change of the phone field. You can also write the same validation in server side plug-in based on business needs and this is fully supported.

    Hope this helps.
      
    -----------------------------------------------------------------------
    Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

     

    Thursday, June 11, 2015 8:29 AM
  • Hi All,

    Used the below script and achieved the requirement.

     

    function ValidateNo(NumStr, String) {
        for (var Idx = 0; Idx < NumStr.length; Idx++) {
            var Char = NumStr.charAt(Idx);
            var Match = false;

            for (var Idx1 = 0; Idx1 < String.length; Idx1++) {
                if (Char == String.charAt(Idx1))
                    Match = true;
            }

            if (!Match)
                return false;
        }
        return true;
    }

    Thanks,

    Sri

     
    • Marked as answer by K_Srinivas Monday, June 22, 2015 1:28 AM
    Monday, June 22, 2015 1:28 AM