Skip to content

Script Examples

Validate Text Length

Download ezUI File

In this example, we will check the length of text entered into a text box. If the length is longer that allowed, we will change the background color or the text box to red.

live log

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// Create a function for the onChange method of the text box with the name "myText"
myText.onChange = (e) => {  

   // Check if the length of the value of the text box is larger than 10 characters
  if (e.value.length > 10){  

    // If the length is larger than 10 characters, change the background color of the text box to red
    e.sender.style.backgroundColor = "red"  

  } else {

    // If the length is 10 characters or less, change the background color of the text back to the default value
    e.sender.style.backgroundColor = "unset" 
  }
}