CRM Dynamics 2013 JavaScript验证自由文本字段中的最小字符数

CRM Dynamics 2013 JavaScript Validate Minimum characters in free text field

本文关键字:字符 字段 文本 2013 Dynamics JavaScript 验证 自由 CRM      更新时间:2023-10-13

我有一个简单的验证,我需要对表单进行验证,它强制用户在字段中包含最少的字符,我有如下代码,但它不起作用,我在加载和保存事件中尝试过,但没有成功,请协助。

function TemsAndCondtitionsValidation()
{
 var TermsandCon = Xrm.Page.getAttribute("new_termsconditions").getValue();
 if(TermsandCon.value.length < 140)
  {
    Xrm.Utility.alertDialog("The length of characters entered are less than the minimum requirement of 140 characters");
  }
}

使用表单编辑器将此函数附加到onsave事件:

function TemsAndCondtitionsValidation(context)
{
    var termsConds = Xrm.Page.getAttribute("new_termsconditions").getValue();
    if(termsConds.length < 140)   {
        Xrm.Utility.alertDialog("The length of characters entered are less than the minimum requirement of 140 characters");
        context.getEventArgs().preventDefault(); // cancel save
    }
} 

如果new_termsconditions是文本类型(单行或多行),您可以简单地修复您的代码,如下所示:

if(TermsandCon.length < 140)