Skip navigation |

Control the length of text entries

You can add validation to your forms to ensure that users must type text of a length that you control. You can add a maximum length, a minimum length, an exact length, or even an upper and lower boundary.

Last updated: 13 May 2010, 10:36

Restrict the number of characters that can be typed

You can validate the text that is entered into a form field to ensure that it contains a specified number of characters.

Text of an exact length

To force your visitors into typing text of an exact length, type the following exactly as shown into the Parameters box of a Single Line Text or a Multi-Line Text item:

^.{x}$

Where x is the length that you require. So, to force text of exactly 5 characters, you would type:

^.{5}$

Text of variable length

To force your visitors to enter text of a variable length, use the following:

^.{x,y}$

Where x is the lower boundary and y is the upper. So, to force text of between 3 and 8 characters, you would type:

^.{3,8}$

Text of a minimum length

To force your visitors to enter text with a minimum length, use the following:

^.{x,}$

Where x is the lower boundary. So, to force text of 5 or more characters, you would type:

^.{5,}$

Text of a maximum length

Visit the following link:
http://www.cubik.co.uk/help/what-can-i-do/forms/maximum-form-field-length

Minimum number of words

To require your visitors to enter a minimum number of words, type the following exactly as shown into the Parameters box of a Single Line Text or a Multi-Line Text item:

^(\b\S+\b\W*){x,}$

Where x is the minimum number of words to be entered. For example, to require your visitors to type at least 50 words, use the following:

^(\b\S+\b\W*){50,}$

Maximum number of words

To require your visitors to enter no more than a specified number of words, use the following:

^(\b\S+\b\W*){,x}$

Where x is the maximum number of words to be entered. For example, to require that no more than 100 words can be entered, use the following:

^(\b\S+\b\W*){,100}$

Variable number of words

To require that your visitors enter a number of words between two values, use the following:

^(\b\S+\b\W*){x,y}$

Where x is the minimum number of words and y is the maximum. For example, to require that your visitors type between 50 and 100 words, use the following:

^(\b\S+\b\W*){50,100}$