|
-
March 11th, 2003, 05:10 PM
#1
Any1 good with Java?
Hey there,
I'm currently doing a piece of coursework for uni involving Java, but i've hit a brick wall, and any help would be appreciated.
I am writing a web page that is a registration form, which asks the user for thier name, address, email, password etc. I have done this and also got it to verify each field isnt blank (if it is an alert pops up), and i have verified the email address is of a valid format and that the password and the verify password match.
What i need from some helpful person is 2 things :-
1)I need to verify fields such as the name field that no numbers have been input and also the telephone number field to make sure no letters or characters have been entered.
2) Once everything has been verified etc, i want a pop up box to say sumthin like, "these are the details you entered", and i need the box to display all the details in the one box (name,address, phone, email etc, but obviously not password).
ANY help would be greatly recieved,
thanks
-
March 11th, 2003, 05:49 PM
#2
Hopefully you are familiar with exceptions. The best way to verify a number field is all numbers, is to read the data as a string, and then attempt to cast it to an integer. Do this in a try{} block and attempt to catch(NumberFormatException e){}. Basically if the exception is caught, there are characters in the string.
To verify the character field contains no numbers is to use a for loop to traverse the string, and make sure each character is not a number (using a really long if statement). There might be a better way, but I can't remember.
The best way to pop up a dialog box is to use the Dialog class.(there are a lot of details involved in using this object, but you can find them out at the URL below)
More info on all of these classes can be found at:
http://java.sun.com/j2se/1.4.1/docs/api/
(This is quite possibly the best java reference site ever)
Good luck!
\"When you say best friends, it means friends forever\" Brand New
\"Best friends means I pulled the trigger
Best friends means you get what you deserve\" Taking Back Sunday
Visit alastairgrant.ca
-
March 11th, 2003, 06:30 PM
#3
I'm really new when doing java, so what u have said is above me. I understand the scripts as there basically c, which i have experience in, so does any1 else have any advice.
Thanks again mate
-
March 12th, 2003, 03:29 AM
#4
Member
Regular Expresions
If you are familiar with perl you should know what a regular expression is. but briefly it´s a way to handle strings and characters, it´s the most powerful tool of perl.
Java also provides a Regex object wich allows you to make those kinds of verification a lot easier and more effective.
try searching java regular expressions . (believe me it´s very useful)
good luck
-
March 12th, 2003, 03:10 PM
#5
OK, first off, it's obvious that you're talking about JavaScript here and not Java. That's what's got the other guys confused a bit. I've yet to see someone implement a HTML form in Java (not because it can't be done, but because it's overkill. So just use a variation of the following code:
Code:
<html>
<head>
<script language="JavaScript">
var name, number;
function validateInput()
{
name=form1.txt_name.value;
number=form1.txt_number.value;
if(!parseFloat(number))
{
alert("Please type only numbers in the \"number\" field");
}
else
{
alert("The values you typed are : \nName="+name+"\nNumber="+number);
document.form1.submit();
}
}
</script>
</head>
<html>
<form name="form1" action="submit.php" method="post">
Name : <input type="text" name="txt_name">
Number : <input type="text" name="txt_number">
<input type="button" name="btn_submit" value="submit" onClick=validateInput()>
<input type="reset">
</html>
If you only want integers, just replace parseFloat(number) with parseInt(number);
Cheers,
cgkanchi
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|