[英]How to LIMIT the text box length?
我正在使用带有rcp的swt jface在Eclipse Java上工作。 我如何限制文本框中的字符。 就像如果我在文本框中只需要4个字符,那我该怎么办? 如果我要字母数字组合怎么办? 再有一定的限制?
请查看此功能示例以限制字符
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);
这对你有用吗?
SWT /限制样式化文字接受的字符数.htm“> http://www.java2s.com/Tutorial/Java/0280_SWT/限制样式化文字接受的字符数.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.