Use Data Validation on the box (in 2007, right-click the textbox and then click "Data Validation", click "Add"; in 2010, click the textbox, click the Control Properties in the ribbon, and click "Manage Rules", then click Add -> Validation rule, then click the condition).
[Update: a comment from a user below highlighted a limit in the solution: line breaks. A better way to accomplish this is to use the 'the expression' in the first dropdown instead of your field and then type "string-length(.)>500" without the quotes]
.{1,500}
See, the Period stands for any character except new line breaks or carriage returns. Now, normally you would put an asterisk after that to mean that you can type as much as you want. Instead, the little braces allow you to place lower and upper limits for the number of characters. The 1 means that they HAVE to type at least 1 letter and the 500 means they get capped off at 500 for data validation purposes.
Now, this does NOT mean that the InfoPath box will STOP letting them type! It just means that, when they tab out of it, it will glow red and have a tooltip that you specify for them when they've typed too many characters. I tested this and it seems to work well for me; give it a try and tell me your results with it!
Hello,
ReplyDeleteGreat post. But when i have tried it. It also gave me a validation error when i typed to ENTER. (But, i typed only 3 characters)
Then, I changed the condition to this: string-length(.) > 255
(Select Expression from first box)
This should allow ENTER (Break Line) characters as well. And these type of characters should count as 2 characters. (\r\n)
The commentor had the correct expression but the tutorial has the wrong <>. Should be string-length(.) > 150 not string-length(.) < 150
ReplyDeleteFixed, thanks.
ReplyDelete