DevelopPHP
home gear home donate
Search Results For
in:

Libraries book

HTML Library CSS Library JavaScript Library PHP Library

Videosbook

PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous

Resourcesbook

Website Hosting Developer Q+A
Length Property
Whether your strings are coming in from external sources for display, or someone is entering text into a form field we created, we can access the number for the amount of characters that the string contains. We can use all of the string comparison operators in ActionScript 3.0 to compare lengths in our conditional statements.

The most common thing a webmaster or web applications creator would use this for is checking the length property of a form field to see if it is empty or not. Then they give a message back to the user saying "Please Enter Your Name", if that is the field the person has forgotten to fill in. We also check many times to see that a username is not too long or short when a person joins our site through a flash registration form. We want everything to be just right. And if it is not just right we do not process a single thing until they get it right.

Note: You can place ( ! ) in front of the variable when using the length property to check if it is empty.

Here is an example of determining the length of a string and giving a message when we run a conditional on it. Both examples comparisons below have identical functionality.
Learn HTML
var string1:String = "";

if (!string1.length) {
    trace("Please enter some text");
} else {
    trace("Your name is " + string1);
}

// ------------------------------------------------

if (string1.length < 1) {
    trace("Please enter some text");
} else {
    trace("Your name is " + string1);
}

Develop PHP browser display window
Please enter some text

Now let's make sure that a user has supplied a username between 5 and 15 characters in character length.
Learn HTML
var userName:String = "Jack";

if ((userName.length < 5) || (userName.length > 15)) {
    trace("Your username must be between 5 and 15 characters");
} else {
    trace("Your user name is " + userName);
}

Develop PHP browser display window
Your username must be between 5 and 15 characters
Home   •   Terms of Use   •   T-Shirts   •   RSS   •   Testimonials   •   Subscribe   •   Classroom Chalkboard   •   Developer Q+A   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties
DevelopPHP.com is a growing educational system packed with video and written material that you can access 24/7 100% free. The focus here in 2014 is spread between five technologies: HTML, CSS, JavaScript, PHP and MySQL. Learn programming theory, database interaction, web design, animation, graphics editing, vector art, 3D modeling, and much more. The educational experience here is a hybrid one offering both high quality video tutorials and code libraries that grow more robust every day. The code libraries are being assembled so that developers can discover all of the building blocks of their favorite languages. The libraries coupled with high quality video tutorials will take you deep down the rabbit hole very quickly. You can also ask questions and get free advice at WebIntersect.com.
HTML5