×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Question Restrict the user to enter alpha numeric and special charectors

    Hi Experts !!
    Could u please tell me ??
    How to restrict the user that it should not enter alpha numeric and special charectors. I'm using J2ME LWUIT.

    Please Reply.
    Regards
    Rajan Verma

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

    Re: Restrict the user to enter alpha numeric and special charectors

    Quote Originally Posted by rajan701v View Post
    Hi Experts !!
    Could u please tell me ??
    How to restrict the user that it should not enter alpha numeric and special charectors. I'm using J2ME LWUIT.

    Please Reply.
    Go through the LWUIT API docs and you will find the following property,
    com.sun.lwuit.TextField.NUMERIC;
    Set this while initealizing the component.
    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
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Restrict the user to enter alpha numeric and special charectors

    Quote Originally Posted by raj_J2ME View Post
    Go through the LWUIT API docs and you will find the following property,


    Set this while initealizing the component.
    If i have to use only charectors a-z,A-Z and 0-9 and some charectors except comma( , ) and semicolon( ; ). in a particular text field then what should i do ??

    Please Reply.
    Regards
    Rajan Verma

  4. #4
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Restrict the user to enter alpha numeric and special charectors

    One more thing i have to remove t9 text from the form. How could i do this ??

    Please Reply.
    Regards
    Rajan Verma

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: Restrict the user to enter alpha numeric and special charectors

    Quote Originally Posted by rajan701v View Post
    Hi Experts !!
    Could u please tell me ??
    How to restrict the user that it should not enter alpha numeric and special charectors. I'm using J2ME LWUIT.

    Please Reply.
    You can do it by using - setConstraint(int) on your TextField.

    For using 2 constraints together use &.

    Refer to API doc.
    PHP Code:
    [B]Input Constraints[/B]

    The TextField shares the concept of input constraints with the TextBox class. The different constraints allow the application to request that the user's input be restricted in a variety of ways. The implementation is required to restrict the user's input as requested by the application. For example, if the application requests the NUMERIC constraint on a TextFieldthe implementation must allow only numeric characters to be entered.

    The actual contents of the text object are set and modified by and are reported to the application through the TextBox and TextField APIsThe displayed contents may differ from the actual contents if the implementation has chosen to provide special formatting suitable for the text object's constraint setting. For example, a PHONENUMBER field might be displayed with digit separators and punctuation as appropriate for the phone number conventions in use, grouping the digits into country code, area code, prefix, etc. Any spaces or punctuation provided are not considered part of the text object's actual contents. For examplea text object with the PHONENUMBER constraint might display as follows:


         (
    408555-1212    
    but the actual contents of the object visible to the application through the APIs would be the string 
    "4085551212"The size method reflects the number of characters in the actual contentsnot the number of characters that are displayedso for this example the size method would return 10.

    Some constraints
    such as DECIMAL, require the implementation to perform syntactic validation of the contents of the text objectThe syntax checking is performed on the actual contents of the text objectwhich may differ from the displayed contents as described aboveSyntax checking is performed on the initial contents passed to the constructors, and it is also enforced for all method calls that affect the contents of the text objectThe methods and constructors throw IllegalArgumentException if they would result in the contents of the text object not conforming to the required syntax.

    The value passed to the setConstraints() method consists of a restrictive constraint setting described above, as well as a variety of flag bits that modify the behavior of text entry and displayThe value of the restrictive constraint setting is in the low order 16 bits of the value, and it may be extracted by combining the constraint value with the CONSTRAINT_MASK constant using the bit-wise AND (&) operatorThe restrictive constraint settings are as follows:

    ANY
    EMAILADDR
    NUMERIC
    PHONENUMBER
    URL
    DECIMAL
    The modifier flags reside in the high order 16 bits of the constraint value
    that isthose in the complement of the CONSTRAINT_MASK constantThe modifier flags may be tested individually by combining the constraint value with a modifier flag using the bit-wise AND (&) operatorThe modifier flags are as follows:

    PASSWORD
    UNEDITABLE
    SENSITIVE
    NON_PREDICTIVE
    INITIAL_CAPS_WORD
    INITIAL_CAPS_SENTENCE
    Input Modes 
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  6. #6
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Restrict the user to enter alpha numeric and special charectors

    You can do it by using - setConstraint(int) on your TextField.

    For using 2 constraints together use &.

    Refer to API doc.
    That's fine i have used this scenario. But what i want is the user enter only numeric(0-9), And alphabetic charector (a-z and A-Z) only.
    But not special charectors like : \!@.,$%^&*><

    I don't want these charectors to be entered by the user. that is it should consume these charectors. Like we have in J2SE textifield textfield.consume(); method.

    Please Reply.
    Last edited by rajan701v; 2011-02-10 at 11:50.
    Regards
    Rajan Verma

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

    Thumbs up Re: Restrict the user to enter alpha numeric and special charectors

    Quote Originally Posted by rajan701v View Post
    That's fine i have used this scenario. But what i want is the user enter only numeric(0-9), And alphabetic charector (a-z and A-Z) only.
    But not special charectors like : \!@.,$%^&*><

    I don't want these charectors to be entered by the user. that is it should consume these charectors. Like we have in J2SE textifield textfield.consume(); method.

    Please Reply.
    I wonder if this can be done in the Native Java ME API, when you are using the High Label API. To do that you have to do it programmatically using the Canvas or using the third party library like LWUIT.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: Restrict the user to enter alpha numeric and special charectors

    Quote Originally Posted by rajan701v View Post
    That's fine i have used this scenario. But what i want is the user enter only numeric(0-9), And alphabetic charector (a-z and A-Z) only.
    But not special charectors like : \!@.,$%^&*><

    I don't want these charectors to be entered by the user. that is it should consume these charectors. Like we have in J2SE textifield textfield.consume(); method.

    Please Reply.
    You need to put a Listener on your TextField and check the text entered by user on every keypress and remove or consume the special char's that you want to avoid. You will get the same effect as J2SE consume.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  9. #9
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Re: Restrict the user to enter alpha numeric and special charectors

    Quote Originally Posted by raj_J2ME View Post
    I wonder if this can be done in the Native Java ME API, when you are using the High Label API. To do that you have to do it programmatically using the Canvas or using the third party library like LWUIT.
    Of course i m using LWUIT. But i don't know how to restrict the user when entering special charectors.

    Please Reply
    Regards
    Rajan Verma

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: Restrict the user to enter alpha numeric and special charectors

    Quote Originally Posted by rajan701v View Post
    Of course i m using LWUIT. But i don't know how to restrict the user when entering special charectors.

    Please Reply
    It's even simple on LWUIT form, just overwrite keyPressed(int key) and keyReleased() methods and do not pass the control to supper() if the user has pressed any special character key i.e. just consume it
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

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

    Thumbs up Re: Restrict the user to enter alpha numeric and special charectors

    Yeah you just keep on checking the key code inside the LWUIT form keypressed() and if this falls under the one which you don't wanna entertain then just don't process the same and repeat this process. For the particular key code don't pass the control to the LWUIT's form.
    PHP Code:
    public void keyPresssed(int keyCode){
         if(
    keyCode is in the range which we dont wanna process){


        }
        else 
    super.keyPressed(keyCode);


    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Replies: 1
    Last Post: 2010-06-30, 06:02
  2. WRTKit TextField and alpha numeric VKB
    By mikah in forum Symbian
    Replies: 0
    Last Post: 2009-08-22, 23:18
  3. Replies: 2
    Last Post: 2007-06-11, 11:45
  4. Translate alpha to numeric
    By Trev-H in forum Mobile Java General
    Replies: 2
    Last Post: 2005-10-07, 16:54
  5. TextBox to enter numeric password Ser 40
    By andretr in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2004-06-14, 20:58

Posting Permissions

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