textfield validation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: textfield validation

  1. #1
    Join Date
    May 2008
    Posts
    32

    textfield validation

    hi,I want to know how cani validate textfield by checking whether there is entry in textfield..,if there is,how to determine whether its valid entry or not...thanq u... was lukin thru api,but it does not seem to do any help....atleast i am not sure whether im looking for anwer at correct place...f sme1 can help me...,t will do betr...

  2. #2
    Join Date
    May 2008
    Posts
    8

    Re: textfield validation

    What would you consider to be a valid textfield entry?

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: textfield validation

    If you want to check whether there is an entry in a text field, just call getText() on it - this will return you the contents for checking. If there is no entry, you should get back an empty String (length 0). It's up to you to decide what a valid entry is, so without more information I can't help you with that.

    Incidentally, your keyboard seems to be playing up - some keys don't appear to be working all the time.

    Imagination is more important than knowledge...
    A. Einstein
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    May 2008
    Posts
    32

    Re: textfield validation

    sorry,I dint make it clear in the first place...what i want to do is to check whether the particular textfield is empty or not..If the textfield is nonempty,I have to check whether the user has inputted the textfiled with the proper text....thanx in advance...

  5. #5
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: textfield validation

    Quote Originally Posted by fairyland121
    ...what i want to do is to check whether the particular textfield is empty or not..If the textfield is nonempty,I have to check whether the user has inputted the textfiled with the proper text...
    I just told you that - textfield.getText() will return the contents as a String. If string.length() returns zero the text field was empty. If not, you can validate the contents of the string.

    If that doesn't answer your question, or you don't understand something, please explain.

    If you can't explain it simply, you don't understand it well enough...
    A. Einstein
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  6. #6
    Join Date
    May 2008
    Posts
    32

    Re: textfield validation

    thanx 4 the help...its working now... I want to know if i can check for alphanumeric characters or special characters in textfiled where i have to write text...

  7. #7
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: textfield validation

    If you want to check individual characters to see if they are letters, digits, whitespace, control characters etc you can convert the string to a char array using the toCharArray() method and then test each character using the methods in the Character class such as Character.isLetter(ch), Character.isLetterOrDigit(ch), Character.isDigit(ch), Character.isWhiteSpace(ch) etc.

  8. #8
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: textfield validation

    Quote Originally Posted by keang
    If you want to check individual characters to see if they are letters, digits, whitespace, control characters etc you can convert the string to a char array using the toCharArray() method...
    Alternatively, you can access them directly from the string using the String.charAt(index) method, e.g. Character.isDigit(myString.charAt(0)).

    Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration...
    S. Kelly-Bootle
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center