473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do i know the type of the input?

9
how can i make the input only string? such as other types like int and double wont be allowed?
what kind of exception shall i use?
Mar 8 '07 #1
5 1420
horace1
1,510 Expert 1GB
how can i make the input only string? such as other types like int and double wont be allowed?
what kind of exception shall i use?
if you are using Scanner
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

you could call hasNextInt(), hasNextFloat(), etc which should all return false.

If your strings should only contain alphabetic characters (no digits) you could use Pattern matching
Mar 8 '07 #2
Salha
9
if you are using Scanner
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

you could call hasNextInt(), hasNextFloat(), etc which should all return false.

If your strings should only contain alphabetic characters (no digits) you could use Pattern matching
I am using GUI and i get the iput from the text field. So if the user enters digits he gets an error msg. But how can i do it?
Mar 8 '07 #3
r035198x
13,262 8TB
I am using GUI and i get the iput from the text field. So if the user enters digits he gets an error msg. But how can i do it?
What if the user enters a string containing digits like r035198x. Would you allow that?
Mar 8 '07 #4
Salha
9
What if the user enters a string containing digits like r035198x. Would you allow that?
NO!! just words, it is a dictionary!!! please help :( my deadline is today!!!!!
Mar 8 '07 #5
r035198x
13,262 8TB
NO!! just words, it is a dictionary!!! please help :( my deadline is today!!!!!
Ah well I was just curious.

Well do you know any regular expressions?
If you don't then you can just write a method called say, hasDigit which returns a boolean

Expand|Select|Wrap|Line Numbers
  1.  public static boolean hasDigit(String s) { 
  2.  //Go through the string's chars one at a time looking for a digit
  3. }  
  4.  
Then you can just use that method.
Mar 8 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jb | last post by:
Hello, I need to know which button was pressed in the submit , i tried reading the vaule of submit it the validateDate function but it returns 'undefined' value ; I do this in asp all the time, Not...
10
by: Eitan | last post by:
Hello, I want to know, wheter an asp (that call itself in "get" method, has passed any parameter to itself). i.e : in the asp : test_asp.asp : ..... <html> <body>
6
by: Fabri | last post by:
I shoul want to know the content o a certain span: ************************************************************************ <html> <head> <title>Documento senza titolo</title> <meta...
12
by: Randell D. | last post by:
Folks, I have a form called "ourTestForm". Its a test form - nothing special - it contains five input tags - they are named one, two, three, four and five. The input tags are of type...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
0
by: Jigar.Patel | last post by:
I have simple remoting server exposing following simple method. When I try to add webreference to this server in another project, it gives me following error: Custom tool error: Unable to import...
10
by: Ken1 | last post by:
Is there a way to know if the user has javascript on? Also, is it a good idea to validate all input in js and php or will this slow down the website?
7
tolkienarda
by: tolkienarda | last post by:
hi all I am using a php script to try to upload images to my database. i know i am connecting to my database because the image title is being wirtten to the database. but the image isn't example:...
9
by: tvnaidu | last post by:
This is just small plain HTML program wtote manually (since I am new to web programming, may be some tools I can use I think), this program loaded onto microcontroller with small foot print web...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.