• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

date validation

 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pals,

first of all i dont have any information about write code with javascript and i need to to some validation on a date ,i wanna check if is the from date & to date in this format or no YYYY-MM-DD..
Any help ??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you written so far? Do you know anything about regular expressions? How to write an event handler that can perform the check? Obtain the field values?

You'll need to write some code and then come here for help with the parts that have you flummoxed.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know all that but some pals told me it's much easier with javascript. is this right?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was talking about JavaScript.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, be aware that performing validation on the client using JavaScript cannot replace server-side validation. Client-side validation is nice for letting the user know that an error has been made at the earliest opportunity, but server-side validation must still be performed.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no i wanna do the validation on the client side this why i went for javascript..
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what if someone turns off JavaScript? What is someone copies your form and submits their own data without your validation? Are you prepared for cross-site scripting attacks?

Data validation must occur on the server in addition to any client-side validation. You can never rely solely on just client-side validation.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oppps , these things never came to my mind may be because this will be internal application and never accessed from outside our network but in general you are right..you you recommend client side and server side validation or just server side?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I prefer both. Server-side validation for the "real" validation, and client-side validation to make things nice for the user.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok , the server side i can do it , but about the client side as i told you i don't know javascript so can you help me in this?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you need to decide at what point you want to validate. Customarily, validation happens at form submission time, but sometimes fields are validated as soon as the user tries to leave them.

Once you decide on that, you need to figure out how to handle the events that are triggered at those points.

Event handling is not an easy introductory JavaScript topic because it is the area in which IE is the most non-standard, and so you need to write lots of cross-browser code to handle the events on all browsers.

To be honest, I'd learn a bit more about JavaScript before tackling this. But if you want to jump in feet first, I'd recommend reading the chapter on Events that I wrote for Ajax in Practice. It's one of the freely available sample chapters for the book. You'll find it here. Click on the link for Sample Chapter 5.

After getting an idea of how painful it is to handle events on your own, it's best to adopt one of the JavaScript libraries that handles the cross-browser nuances for you. The sample chapter shows how to use Prototype for this, but jQuery also has really good event handling APIs (in fact, a bit more powerful than Prototype's).

Once you've got the event handling down, then it's time to go on to the next subject: grabbing and validating the data.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sherif,
Don't trust those internal users too much either. What happens if you have a disgruntled employee who decides to wreck the database? The fact that they could enter - say a SQL query - in your text field and run a delete would be a really bad thing.

Bear,
I understand how event handling in AJAX isn't an easy introductory topic. But what's so hard or browser specific about onblur or onsubmit? I'm assuming Sherif isn't using anything more complicated if he doesn't know much JavaScript.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even the simplest event handling needs to deal with the differing Event instances and the manner in which they are obtained.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Even the simplest event handling needs to deal with the differing Event instances and the manner in which they are obtained.



Even something as simple as this:


Sorry for the thread tangent. I'm really trying to understand what complexity I'm missing.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your handler is hard-coded to check a specific field. Most forms have many fields that need to be checked, and the only way to create a common handler would be to use the Event instance to discover the triggering component.

Sure, there are trivial cases where you may not run up against browser differences, but as soon as event handling needs to do anything of substance, those differences are right there in your face -- I have the lack of hair to prove it!
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Your handler is hard-coded to check a specific field.


Fair enough. I guess my point is that Sherif could hard code his date field to get going before he understands all the details of event handling.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:

Fair enough. I guess my point is that Sherif could hard code his date field to get going before he understands all the details of event handling.



Ya , and i prefer that too specially i got strict time frame, Thanks pals for your support...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case, you can start with Jeanne's example and adapt it to your own use. You will find that JavaScript regular expressions will be useful to test the input against a pattern.
 
reply
    Bookmark Topic Watch Topic
  • New Topic