The Artima Developer Community
Sponsored Link

Java Answers Forum
check if input is String?

4 replies on 1 page. Most recent reply: Jan 13, 2004 5:08 AM by morki

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
morki

Posts: 4
Nickname: sheva7
Registered: Jan, 2004

check if input is String? Posted: Jan 12, 2004 2:47 PM
Reply to this message Reply
Advertisement
Hi, I'm wondering how I can check an input for a String. It has to be a String! If someone types a number the catch statement must identify the input as an Integer, giving a warning!
The other way around is ...catch (NumberFormatException e) {...}

thx!!


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: check if input is String? Posted: Jan 12, 2004 7:50 PM
Reply to this message Reply
I am not sure what u want...but checking instanceof may help.

Also for number u can compare char value shuldnt be b/w 0-9 ...
there can me many ways

morki

Posts: 4
Nickname: sheva7
Registered: Jan, 2004

Re: check if input is String? Posted: Jan 13, 2004 1:05 AM
Reply to this message Reply
I mean:
if you have a textfield where one MUST enter only characters. If user then inputs numbers, program must catch this and give a warning like "only characters..."

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: check if input is String? Posted: Jan 13, 2004 1:08 AM
Reply to this message Reply
U can add either KeyListener to the text field or the documentListener to the textField and on keyPressed/keyTyped event can check if char typed is between 0-9 stop him

morki

Posts: 4
Nickname: sheva7
Registered: Jan, 2004

Re: check if input is String? Posted: Jan 13, 2004 5:08 AM
Reply to this message Reply
okay thx
I'll try to come up with some code..

Flat View: This topic has 4 replies on 1 page
Topic: example query in java? Previous Topic   Next Topic Topic: security policy code

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use