views:

221

answers:

1

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?

+1  A: 

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;}
  } 
Karthik
Is that Javascript?
Nitrodist
Yes javascript only
Karthik
I m nt using javascript.should this be done as a validator to text box? if yes ,,,,,,how?
sam
not getting your point. Explain your need in detail
Karthik
I am using eclipse RCP.In my editor i have a text box.I want to set a limit on the text entered in the text box so that whenever user tries to enter a text more than 8 characters.it should not accept it.
sam
for this one, you have to use js only.
Karthik
check this url :http://www.mediacollege.com/internet/javascript/form/limit-characters.html
Karthik