Sometimes we have situations where we have to fill only alphanumeric value in the given field (like: password, user id etc). Alphanumeric value is a combination of alphabets and numeric value. In MS CRM 2011 we solve this problem by writing java script to validate whether the value which was filled on the related field is alphanumeric or not. We can validate alphanumeric value with use of this code:
function validatealphanumericvalue(){
var field= Xrm.Page.getAttribute("CRMFieldName");
if(field && field.getValue()){
var pattern = /^[0-9a-zA-Z]+$/;
var fieldVal = field.getValue()
if (pattern.test(fieldVal)){
return true;
}
else{
alert("Please fill alphanumeric value");
event.returnValue=false;
}
}
}
Note: Add this code into your java script web resource and then call it On Save event of the form.