• Post Reply Bookmark Topic Watch Topic
  • New Topic

validating date in registration form  RSS feed

 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the below program am getting java.text.ParseException: Unparseable date: "11/02/2013". How to get rid of this please some one help me asap. need to submit this tomorrow.

 
Paweł Baczyński
Bartender
Posts: 2076
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your date format is "mm-dd-yyyy" and you try to parse "11/02/2013" .
What could go wrong?

I have some questions about your validating methods.

So isValidAge only checks for String length.
So an age "dsiubv8iy" is valid, right?

isValidLname check if String is empty and does not contain "-".
So "@#$%^&*\n\n\r\t\u0001\u7123______________\r\n\r\u5fb5\n\r\n" is valid but "Skłodowska-Curie" is not?

isValidContNo check only for length so "\r\n\t\r\n\t\r\n\t\r" is a valid cont number?

A hint:
When you validate data passed by user assume that the user is an crude idiot and will pass you anything. For example They might put "dsiubv8iy" as their age.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it is november 02nd 2013. hope you got it right.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sunaina agarwal wrote:yes it is november 02nd 2013. hope you got it right.

Pawel's got it right; but you plainly haven't.

Have a look at his post again. Carefully.

Winston

PS: Please DontWriteLongLines. It makes your thread very hard to read, and it's actually bad coding practice. I've broken yours up this time.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also go through the SimpleDateFormat documentation and find out what m means.
 
Paweł Baczyński
Bartender
Posts: 2076
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Also go through the SimpleDateFormat documentation and find out what m means.

Ah! I missed that!

Another hint:
I see that your code has comments likeorIf you indented your code correctly they wouldn't be necessary.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote: . . . Ah! I missed that! . . .
That is the good thing about a forum like this. Many people read the code and the chances of something being missed are much smaller. We have all missed things and had somebody else pick them up.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Pawel Pawlowicz, Campbell Ritchie and Winston Gutkowski for the corrections am really thankful. i Got it right now...
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done Please show us your current pattern.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure Campbell Ritchie once am done i will definitely post it. and between i have a doubt is there any way to validate address like street name, cross, main like that,
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can probably validate that sort of thing with a regular expression, but beware: What about places which don't have a street address? You might have Manor Farm, Great Badding. Name of place, and no street. You have to consider that a valid address here in Britain.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You can probably validate that sort of thing with a regular expression, but beware: What about places which don't have a street address? You might have Manor Farm, Great Badding. Name of place, and no street. You have to consider that a valid address here in Britain.

Being raised here in the colonies, we tend to forget that other places throughout the world don't always have what we would consider a "proper" address consisting of a house number, a street name and suffix, city, state, and zip (postal code). There was another post in the last day or so that described this problem -- the OP was required to enter his house number when in fact he did not have one. The program refused to let him move on until he corrected his "mistake". Thirty years ago we could get away with such short-sighted programming, but not in this day and age when you can get to any corner of the world in a handful of hours.

Oh, and the bit with the definition of 'm' -- I must have looked at that half a dozen times puzzling the problem you hinted at. Just as I was about to break down and read the simple date format notes the lightbulb came on and left me with another 'doh' moment.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert D. Smith wrote:Being raised here in the colonies, we tend to forget that other places throughout the world don't always have what we would consider a "proper" address consisting of a house number, a street name and suffix, city, state, and zip (postal code)...

Well, there are a few things that may be universal. In both the US and the UK, for example, every address (except possibly Buckingham Palace and 1600 Pennsylvania Avenue) has a postcode. Furthermore, if you know the postcode, things like city and state are usually redundant (although they may provide a useful "double-check").

In Madagascar, however (I have a friend whose wife is from there), you may well have an address like:
3rd house on the left, <Some village>

Conversely, even if you include ALL the things you're supposed to, viz:
The Pentagon, 1400 Defense Pentagon, Arlington, VA, 22211.
you've only narrowed it down to ≈31,000 people.

Basically, addresses, like people, are VERY difficult to rationalize 100%; so my advice is to treat it as free-form text unless there are components, like a postal code, that you know you can mandate.

Winston
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Campbell Ritchie... Please go through the code. I have modified it as per every ones suggestion here. and thank you Winston as you have posted i have left the address field as free-form text .

 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please can anyone tell me how to display the errors in the field...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!