×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Validates the size of a text message

    Hi all.

    I am trying to write a Midlet that can Validate the Size of a text message so as to make sure that the text that a user of my application submit will not be too large. Is there any help on the source code to do this and how to do this? This will be much appreciated. Thanks

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Validates the size of a text message

    Hi,
    Where you are taking the text message..I mean ..where the user enter the chars ..in text field or canvas..
    @In the first case you need not to count ..simply device will display the same for you..
    @In the later case..if taking the input on canvas then follow like this.
    Take int countSmsIndex = 0;
    As soon as the increase that counter by one...ok
    keep this process ..as long as you want that user enter the chars.If after a fix number you want to stop the user then display an alert that..you can not enter the more chars..

    Make note that generally sms text length supported by the most devices is 160.

    Hope these lines can help you..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    65

    Re: Validates the size of a text message

    Are u using Textfield ? is so use ItemStateListener and check for the length of the test using getString() method of TF, every time the user enters a new Char. Then u could throw an alert.
    IF u are using custom Canvas TF then add each char to a string and check the length of the string every time the user enters a new Char. Then u could throw an alert.
    Thanks and Regrads
    Pradeepcg

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: Validates the size of a text message

    raj_J2ME and Pradeepcg, thanks for your response. But I am working with a textfield where the user enters the text. I want to set the limit and raise alarm after that time. Say for example a user should not enter more than 10 Characters then after that 10 character an alert will pop up telling the user that it can only enter 10 character. Thanks

  5. #5
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    166

    Re: Validates the size of a text message

    Use this
    TextField tf;
    tf.setMaxSize(int size);

    this will avoid user from exceeding number of chars
    and if you want to alert user for chars exceeded then check if char entered tf is equal to size if true than alert that no more chars can be entered

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    4

    Re: Validates the size of a text message

    try this sample http://freesrc.com/?p=151

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: Validates the size of a text message

    Hi,

    I understand but my problem is that I dont want to send the size of the text myself. All I want to do is that I want the user to enter the text and after entering a say 30 character is the limit then I want the system to display an alert to say the user can't enter more than 30 Character. Thank

  8. #8
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Validates the size of a text message

    Hi,
    As the different views has come...and hope that you did it..
    Though I am writing the logic..
    You can move like -
    // 1 create a text field
    private TextField pass = null;
    pasw = new TextField("Password:", "", 30, TextField.PASSWORD);
    //2 Validate size
    if(pass.length() > 6 )
    {
    //show the alert//

    }
    hope this help you,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: Validates the size of a text message

    Thanks Raj_J2ME and others. If you look at the text box parameters:

    public TextBox(String title, String text, int maxSize, int constraints)

    This means that I have to specify the maximum size. If this is done there is obviously no need and no way of displaying the alert because the textbox itself will not allow user to enter more than 30 and any attempt to go beyond 30 will automatically not work. In the other sense if I dont include the "int maxSize" param in my declarartion (as we can see everyone responded to me also included that declaration)then I will get an error message. I am looking for a way to go around this. Any help still

  10. #10
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Validates the size of a text message

    Hi,
    pasw = new TextField("Password:", "", not given, TextField.PASSWORD);

    then you can use this code to check the same -
    if(pass.length() > 6 )
    {
    //show the alert//

    }
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  11. #11
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    166

    Re: Validates the size of a text message

    you can add one more textfield and set a default value say 30 and can be changed

    and for textfield where u want to add alert check the size with above textfield's size if greater then throw alert

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: Validates the size of a text message

    I will appreciate if you can explain what you mean in Code mahesh_aquarius. raj_J2ME, the last code is not going to work, the parameter must be passed into the maxSize. Thanks

  13. #13
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    166

    Re: Validates the size of a text message

    You let the user enter what size he wants
    Suppose you have

    TextField main=new TextField("Data",null,120,TextField.Any)
    TextField dummy=new TextField("Enter Length of Data","30",120,TextField.Numeric)

    String temp=dummy.getString();
    String data=main.getString();

    if(data.length()>temp)

    Display alert


    Hope thats wat u wanted

  14. #14
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Validates the size of a text message

    Hi,
    Though the post of mahesh is perfect..though -
    Let me make it more clear,
    @ Have your textfield,
    private TextField password;
    @ create it,
    password = new TextField("Password:", "", 10, TextField.PASSWORD);
    Make note that..the number either you can provide the exact what you need like 10..or suppose you provide like 100.
    @ Apply check -
    Suppose you provide the number as 100...however you want max as 6 then
    if(password.getString().length() >= 6)
    {
    show some alert..


    }

    for the more query you can write here,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. KERN-EXEC 3 with CEikEdwin
    By acarrion in forum Symbian User Interface
    Replies: 3
    Last Post: 2007-10-17, 14:43
  2. Long text message in CSmsClientMtm
    By ericyklee in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-03-13, 07:45
  3. send text file to message
    By khemarak_168 in forum Symbian
    Replies: 3
    Last Post: 2007-01-22, 05:41
  4. nokia 6220 text size
    By rjlafayette in forum General Development Questions
    Replies: 0
    Last Post: 2004-08-17, 18:04
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×