1

我正在使用带有rcp的swt jface来处理eclipse java。如何限制文本框中的字符。就像我只想在文本框中输入 4 个字符,那我该怎么办?如果我想要字母数字组合怎么办。又在一定限度内?

4

3 回答 3

1

这是答案的一半:

text.setTextLimit(4);
于 2017-06-22T09:20:37.333 回答
0

请查看此函数示例以限制字符

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;}
  } 
于 2010-04-20T05:09:43.640 回答
0

这对你有用吗?

SWT/限制StyledText接受的字符数.htm">http://www.java2s.com/Tutorial/Java/0280_SWT/LimitthenumberofcharactersthatStyledText接受.htm

于 2011-02-28T17:09:37.077 回答