locked
OnkeyPress event in crm 2011 RRS feed

  • Question

  • I want to validate phonenumber on keypress event of text filed

    111-111-1111

    I done that work in crm 4(below code) but it does not work in crm 2011

    onload I write that code in crm 4

    ValidateCharacters = function() {
    var x=crmForm.all.telephone1.DataValue;
        var key = event.keyCode;
        if(key >= 48 && key <= 57) {
    if(x.length <12){
    if(x.length==3){crmForm.all.telephone1.DataValue=x+"-";}
    if(x.length==7){crmForm.all.telephone1.DataValue=x+"-";}

            event.returnValue = true;
            return true;

    }else{return false;}
        }
        else {
            event.returnValue = false;
            return false;
        }
    }

    crmForm.all.telephone1.attachEvent('onkeypress',ValidateCharacters);

    how to change that in crm 2011.

    Friday, May 25, 2012 9:45 AM

Answers

  • I have a blog post the covers something similar. 

    Use something like:

    document.getElementById("telephone1").attachEvent("onkeypress", KeyPress);
    

    Jason Lattimer

    Friday, May 25, 2012 1:35 PM
    Moderator

All replies

  • I have a blog post the covers something similar. 

    Use something like:

    document.getElementById("telephone1").attachEvent("onkeypress", KeyPress);
    

    Jason Lattimer

    Friday, May 25, 2012 1:35 PM
    Moderator
  • You can maybe add the validation code to the onChange event of the telephone1 field.  It will then be validated as soon as the user goes out of the field.

    Please vote if you find my post useful. Add me on Skype @ christo.skype1

    Friday, May 25, 2012 2:48 PM