locked
CRM 2011 alphabets field RRS feed

  • Question

  • Hi

     I have city as text filed.. but it's allowing alpha numerics.. i want to all only alphabets...

    can you pls suggest it how can i do it?


    Rammohan

    Tuesday, October 23, 2012 10:36 AM

Answers

All replies

  • Hi Ramminhan,

    This is not possible out of the box - there is no way you can put a mask on top of the field, make regexpressions or format the field the way you like.

    You need to create some javascript code that subscribe to the keyup event on the field.

      


    --- Best regards Henrik Skydtsgaard


    Tuesday, October 23, 2012 10:47 AM
  • Tuesday, October 23, 2012 10:49 AM
    Answerer
  • Hello,

    I did this for CRM 4.0. You will have to port this code to make it for CRM 2011.


    Freelance Developer for Dynamics CRM 4.0/2011

    Tuesday, October 23, 2012 11:01 AM
    Moderator
  • Hi


    function SwitchOnCheck()
    {
     var element = Xrm.Page.data.entity.attributes.get ('fulltimeagent');
     if (element != null)
     element.attachEvent("onkeyup", function()
                           {
          var mikExp = /[1\\2\\\3\4\5\6\7\8\9\0\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|]/;
          var strPass = element.value;
         if (strPass == null)
         return;
     var strLength = strPass.length;
     var lchar = element.value.charAt(strLength - 1);
     while(lchar.search(mikExp) != -1)
     {
      strPass = strPass.substring(0, strLength - 1);
      if (strPass.length == 0)
       break;
      strLength = strPass.length;
      lchar = strPass.charAt(strLength - 1);
        }

     element.value = strPass;
    });  
    }

    i called the same  in changeevent for that particular control.. but it's not working...

    can you one check it pls.. my requirement is ..field should allow to enter numbers and special characters


    Rammohan

    Tuesday, October 23, 2012 11:49 AM
  • Hi Rammonhan

    Have you tried to debug it, to see if you actually hit the event. In the case you hit the event, when do the function return?


    --- Best regards Henrik Skydtsgaard

    Tuesday, October 23, 2012 12:13 PM
  • Hello,

    Try to use following code:

    FilterCharacters = function(fieldname)
    {
        document.getElementById(fieldname).attachEvent("onkeypress", function()
        {
            var allowed = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
            var pressedkey = String.fromCharCode(event.keyCode);
            if (allowed.indexOf(pressedkey) != -1)
                return true;
    
            return false;
        });
    }
    
    OnLoad = function()
    {
    	FilterCharacters('fulltimeagent');
    }


    Freelance Developer for Dynamics CRM 4.0/2011

    Tuesday, October 23, 2012 1:57 PM
    Moderator
  • Hi Andrii,

     I'm not understand the function.. can you please explain bit more..  FilterCharacters = function(fieldname)

    OnLoad = function() these two lines of code i cound't understand.. i am working on MSCRM 2011.. is it support?

    i traied.. but not working...

    can you suggest it.. how to call those functions where i have to call it?

    -Regards,

     Rammohan


    Rammohan

    Thursday, October 25, 2012 4:00 AM
  • As for me everything is obvious:

    Function called OnLoad should be called during OnLoad event of form.

    FilterCharacters function that is called in OnLoad function adds handler to OnKeyUp event (of control name of which is specified as a parameter). This handler blocks entering of disallowed characters.

    PS Please stop click "Unpropose" button. All suggested replies partially answer your question.


    Freelance Developer for Dynamics CRM 4.0/2011

    Thursday, October 25, 2012 6:32 AM
    Moderator