Calculate Character and Word Counts for a Form FieldPRO

You can use WS Form PRO to calculate the number of characters or words in a form field. You can also incorporate this with other calculations, for example you could multiply the number for characters by 10 in a Price field.

Demo

Character Count

Syntax: #field_count_char(field_id, "regex_filter")

To get the number of characters in a field, you could use:

#calc(#field_count_char(123))

… where 123 is the ID of the field. The #calc variable ensures the value is updated whenever the source field changes. You would typically add this to the default value of a field.

The calculation can also be filtered by using a JavaScript regular expression. For example:

#calc(#field_count_char(123, "/[^0-9a-z]/gi"))

This would only include alphanumeric letters in the character calculation, i.e. spaces would not be included.

Furthermore you can also use the #field_count_char variable alongside arithmetic within the #calc variable. For example:

#calc(#field_count_char(123, "/[^0-9a-z]/gi") * 10)

This would multiple the count of alphanumeric characters by 10.

Word Count

Syntax: #field_count_word(field_id, "regex_filter")

To get the number of words in a field, you could use:

#calc(#field_count_word(123))

… where 123 is the ID of the field. The #calc variable ensures the value is updated whenever the source field changes. You would typically add this to the default value of a field.

Furthermore you can also use the #field_count_word variable alongside arithmetic within the #calc variable. For example:

#calc(#field_count_char(123, "/[^0-9a-z]/gi") * 10)

This would multiple the count of alphanumeric characters by 10.