How to Set a Limit for your TextBox object!

5

Attached Files

The following files have been attached to this tutorial:

.capx

textbox-limit-demo.capx

Download now 85.12 KB

Stats

6,570 visits, 9,912 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 12 Nov, 2013. Last updated 19 Feb, 2019

Overview

This simple tutorial will show you how to set a character limit for your textbox object. This is handy for ensuring users do not go crazy with username lengths, also preventing display errors in future.

The implementation

We'll use the 'len' expression to return the number of current characters entered in the textbox and then set a condition to compare it to the max character count of our choosing, like so:

    len(EnterNameBox.Text) >= 11


To do this, click 'Add Event' or right-click on empty space > Add Event; then double click on 'System' and then 'Compare Two Values'.

NOTE: We use 'Greater than or equal to' instead of equals to prevent a bypass of typing multiple characters rapidly.

Then enter the following:

Hint:

First value: len(TextBox.Text)

Comparison: >= Greater than or equal to

Second value: 11

Change 'TextBox' to the name of your object and '11' to your character limit.

Now click on 'Add action', then double-click on your textbox > Set text and type

    left(TextBox.Text, 10)

The 'left' expression simply returns the first amount specified (e.g. 10) of characters in a text string.

This means that trying to type 'Insert text here' will only allow 'Insert tex' to show.

NOTE: Spaces count towards the character limit.

Example:

Display a message when limit is reached

Create a text object and set the text to 'Max 10 Characters' then set visibility to invisible in the properties. You can optionally add the fade behaviour and set properties to something like:

Wait time: 1

Fade out time: 1

Add actions(to previous condition):

Text > Set Visible

Text> Fade: restart fade

Other Uses:

Display a 'Press Enter to continue' when limit reached or a button.

Download the CAPX to see a demonstration.

Enjoy!

.CAPX

textbox-limit-demo.capx

Download now 85.12 KB
  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!