Out of the box you can't set a maximum length o a field, just a maximum value. So if you want to control the length you'll need to use some JavaScript and/or a plugin.
Here is an example of the JavaScript:
function Field_OnChange() { var value = Xrm.Page.getAttribute("numericfield").getValue(); if (value.toString().length > 10) { alert("Too Long"); } } function Form_OnSave(executionObj) { var value = Xrm.Page.getAttribute("numericfield").getValue(); if (value.toString().length > 10) { alert("Too Long"); executionObj.getEventArgs().preventDefault(); } }
Hook up the OnChange event of the field and also the OnSave event of the form (make sure to check the box to pass the execution object here).
You can't change the data type of a field once it is created but you can do something similar to strip out the non numeric characters.
Something like:
function Field_OnChange2() { Xrm.Page.getAttribute("fieldname").setValue( Xrm.Page.getAttribute("fieldname").getValue().replace(/[^0-9]/g, '')); var value = Xrm.Page.getAttribute("fieldname").getValue(); if (value.toString().length > 10) { alert("Too Long"); } }