Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Restrict/Limit Length for field dynamically using JAVA Script


Level 2


     How do I dynamically restrict the lenght of the field? I could not use the maxChars property as it cannot be directly addressed. Based on certain conditions I would like to dynamically retrict the field length to 2 characters. Can anybody help?

I am able to capture the length using the below code: -


maxLen = this.value.oneOfChild.maxChars;

but how do I restrict the length of the field to 4 characters only ?



1 Reply


Former Community Member

Something like this will work.

// form1.page1.subform1.productID::exit - (JavaScript, client)

if (form1.page1.subform1.productID.isNull) {

  xfa.host.messageBox("The product ID is a mandatory field.");


else {

  var productID = this.rawValue;

  if (productID.length != 4) {

    xfa.host.messageBox("The product ID must be four characters in length.");



This code assumes the product ID is a mandatory field.