简体   繁体   中英

CRM Dynamics 2013 JavaScript Validate Minimum characters in free text field

I have a simple validation that I need to perform on the form where it forces the user to have a minimum amount of character in a field, I have the below code as follows, but it does not work, I tried it on load and on save event but no luck, please assist.

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");
  }

}

如果new_termsconditions是text类型(单行或多行),则可以像下面这样简单地修复代码:

if(TermsandCon.length < 140)

Use the form editor to attach this function to your onsave event:

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
    }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM