javascriptlivecycle-designer

Match a LiveCycle decimal field to a pattern


We have a decimal field in a LiveCycle Designer-designed PDF form that is intended to capture a latitude value. I want to make sure that the users enter exactly three decimal places. And I don't want the PDF to create the decimal digits for them. The user must enter them.

I tried to capture any improperly entered values using a this.rawValue.match(myRegEx) method as shown below in the field's exit event, but JavaScript threw the following error:

TypeError: this.rawValue.match is not a function
17:XFA:form1[0]:Page7[0]:Facility_Coord_Latitude[0]:exit

Here's the code I was using. This is confusing because I use this exact approach on a different field. Although that other field is a text field and this one is a decimal field. Maybe the "match" method doesn't work for decimal fields? Any way to convert the decimal value to a string to which I can use the "match" method? Or any other ideas for how to do this?

if (this.rawValue != null){ // only if the field has a value...

    if (
    !this.rawValue.match(myRegex1) && 
    !this.rawValue.match(myRegex2)){ // it doesnt match any of the patterns
    
        xfa.host.messageBox('Please enter your value to exactly three decimal places.');
        xfa.host.setFocus(this.name);
        
    }
    
}

Solution

  • With @CertainPerformance's advice, I figured out the decimal field was indeed not a string. I tried converting to a string as follows in my validation code:

    String(this.rawValue).match(myRegex2)

    That worked partially, but it failed if the user entered "000" as the three decimal digits, I think because the decimal field would truncate those trailing zeros before it passed the value to be checked. So, I think the answer is there's no way unless I convert the field from decimal to text.