locked
how to match a input value with the regular expression in dynamics crm 2011? RRS feed

  • Question

  • Hi,

    At the contact form I have a field name as Extension (new_ext). and at the onChnage event I want to do check weather the user has enter the number or anything else. I have the following piece of code.

    function formatPhone(phonenum)
    {
    var ext =phonenum.getEventSource().getValue();
      var reg = /^[0-9]$/;
    if(ext.match(reg))
    {
    alert("Valid");
    }
    else
    {
    alert("invalid");
    }
    }

    It returns me always invalid even if I enter a letter or a number or both.

    I want to seek your kind suggestions and help regarding this.

    Thursday, February 6, 2014 2:09 PM

All replies

  • Check this blog

    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    Thursday, February 6, 2014 2:36 PM
  • Hi,

    You should use ext.test(reg) instead of ext.match(reg). Ext.match(reg) won't return true/false but rather the parts that match the "reg", which will make the "if(ext.match(reg))" turn into "if(555-3434)" which probably isn't what you're aiming at. That it's working at all in some fashion is sort of amazing, you would think it would break on the if statement.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Thursday, February 6, 2014 3:35 PM
  • @Mamatha is there any mean to fire the JS events like onKeyPress in CRM 2011 form of any entity, But m working on Case?
    Friday, February 7, 2014 2:12 AM
  • Ali, OnChange is the only supported field event (any entity's form field). Am not aware of an unsupported way to trigger other JS events and would not recommend it as it would more likely break your CRM 2013 upgrade. Try talking to your users on the right way to do the format validation in MSD CRM.


    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    Friday, February 7, 2014 2:53 AM
  • Friday, February 7, 2014 9:01 AM