简体   繁体   中英

How to LIMIT the text box length?

I am working on eclipse java using swt jface with rcp. How can i limit the characters in my text box. Like if i want only 4 characters in my text box then what should i do? and what if i want alphanumeric combination . again in certain limit?

Please look this function example for limit the character

function check_length_year(my_form) {
  maxLen = 4; // max number of characters allowed
  if (my_form.retire_year.value.length > maxLen) {
  // Alert message if maximum limit is reached.
  // If required Alert can be removed.
  // var msg = "You have reached your maximum limit of characters allowed";
  // alert(msg);
  // Reached the Maximum length so trim the textarea
     my_form.retire_year.value = my_form.retire_year.value.substring(0, maxLen);
     return false;
  } else { // Maximum length not reached so update the value of my_text counter
     my_form.year_num.value = maxLen - my_form.retire_year.value.length;}
  } 

那是答案的一半:

text.setTextLimit(4);

does this work for you?

SWT/LimitthenumberofcharactersthattheStyledTextaccepts.htm">http://www.java2s.com/Tutorial/Java/0280_SWT/LimitthenumberofcharactersthattheStyledTextaccepts.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM