CRM2011 Account Name validation


Special Characters and Uppercase:-


function onSave(ExecutionObj)
{
    var _customername = Xrm.Page.getAttribute("name").getValue();
    if (_customername != null && _customername.trim().length > 0) {
        _customername = _customername.trim();
        var validateresult = _customername.match(/[a-zA-Z0-9&-\s']/g);
        if (validateresult == null || (validateresult != null && validateresult.length != _customername.length))
        {
            alert("Only special characters (&,-,') are allowed for a customer name: " + _customername );
            ExecutionObj.getEventArgs().preventDefault();
            return false;
        }
        if (_customername.indexOf("'") > 0)
        {
            if (_customername.match(/[A-Za-z]'/g) == null)
            {
                alert("It should not be allowed to use space at the front of '(single qoute) character for customer name.");
                ExecutionObj.getEventArgs().preventDefault();
                return false;

            }
        }
        _customername = _customername.toUpperCase();
        _customername = _customername.replace(/&/g, " & ").replace(/-/g, " - ");

        Xrm.Page.getAttribute("name").setValue(_customername);

    }
}

Post a Comment

0 Comments