Can I program field properties data entry rules?

In a data sheet, within Field Properties, is it possible for a text field to require a specific # of characters (in this 4)?

And/or, is it possible to display an error message if 4 characters are not entered?

Or, do I make a form and handle this within a form?

Thanks.

One heavy handed way to do this would be to install some code in the Code tab of the Properties panel for your field. Say your field name is “MyField” you could enter code like this:

If length(Category)<>4
field MyField
Message “MyField entry must be a 4 character string!”
wait 0
editcell
endif

This will check the length of the entry in MyField and give an error message if the length is not 4 characters long and then reactivate the field for further data entry.

What you are asking for used to be very difficult/impossible but Panorama 10.2 added the ability to set up fully custom validation.

In your case the code would be:

validateFieldInput: 
    functionvalue(length(_VALUE_) = 4)
    return

This will work in both the data sheet and in forms.

Update: This code is incorrect, see my post below for the correction.

By golly, that one slipped past me completely. I can actually take advantage of this new feature in the project I’m working on right now. Cool!

Amazing…Gary/Jim - thank you.

Not sure why, but nothing is happening. The field QTY is a text field, and when I use this code in the Formula box, there are no warnings (the Editor Mode is set to Automatic)…

return

validateFieldInput:
functionvalue(length(VALUE) = 4)
return

I should get an error message when the entry is less than 4 digits.

I also tried…

return

validateFieldInput:
if functionvalue(length(VALUE) = 4)
functionresult true ()
else
functionresult “Not enough digitss”
endif
return

What am I doing wrong?

It goes in the code box, not the formula box. Also _VALUE_ begins and ends with an underscore. You left the underscores off.

He probably had them in his original text and they were interpreted as tokens to make VALUE italic.

I checked that after I posted, and found asterisks in his raw text, which also would have made them italic. Not sure how that would have happened.

I t looks like if the text entry box is set to Rich Text the underscores are italic tokens. If tlhe entry box is set to Markdown they are not.

I tried this with ‘return’ at the top and not at the top. I enter a single digit in a text field and there is no error message.

Still not working…

I can’t get the validateFieldInput method to work either. I tried several variations and never got any alert messages at all. The only way I got it to beep and not close the edit box is if I replaced the underline characters with ellipsis characters. Seems strange to me.

I ended up just going with a version of my original code. Note in my case I need 12 digits entered into the field.

if length(_VALUE_)<>12
alertok “Field must contain 12 digits!”
endif
return

Note: Panorama X version 10.2.2 (4595) - Mac OS Tahoe 26.3.1

Sorry, I made a slight mistake in the code - functionvalue is a statement, not a function. The correct code is:

return

validateFieldInput: 
    functionvalue length(_VALUE_) = 4
    return

Though I messed up my submission above, the documentation does show the correct code.

I tested it just now and it worked fine.

1 Like

Yep, that works perfectly and displays the alert if the length of the input is not correct.

Magic. Thank you.