Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in JSP Validations  RSS feed

 
Momina Khan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello and hi,
i am momina khan. This is my very first message in javaranch fourms. I am applying validations in JSP. I dont want to use java scripting. One of my JSP field is phone number. I want to access to the user to enter only (0123456789+-) in phone text field. I will be very thankful to you if you will help me. I am waiting......
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Momina, welcome to the Ranch.

Here's a helpful tip: adding phrases like "I am waiting" (as well as things like "Urgent" and so on) are usually considered rude and off-putting. If you want people to help you, it would be best to refrain from such language.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With regards to your question, if you want to do client-side validation, you must do it with Javascript. No way around it.

For server-side validation, which you should do regardless of whether you do client-side validation or not, the servlet to which your form is submitted can validate the field and return to the form page if not correct. Request-level scoped variables can be used to issue error messages and other information.
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Momina Khan

Hearty Welcome to JavaRanch. I am sure that you will enjoy this

Your problem will become simple if u use a client side validation.

As Bear pointed out rightly,
With regards to your question, if you want to do client-side validation, you must do it with Javascript. No way around it


I too am going by his words. And one more advantage is that u can handle the field being null in the client side itself.

Or else, u might have to handle Null Pointer Exceptions adn that's a headache.

It is better to do all possible validations in the client and pass only the appropriate parameters to the server...so that u get the expected results.

If you need any help, u r most welcome.

Cheers,
Swamy
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is better to do all possible validations in the client and pass only the appropriate parameters to the server...so that u get the expected results.


I completely disagree. Apparently Swamy only read part of my response.

Client-side validation is there for the benefit of the user only. It allows you to give them quick feedback when you can detect problems with their data entry without making them wait for a server round trip. But that is the extent of its utility.

Your server-side code should never ever ever ever, and did I mention ever, assume that client-side validation has taken place.

Why?

On the practical side, the user may be using a browser with Javascript turned off, or with a shoddy/non-existant Javascript implementation. On the security side, a malicious user can be hitting your site with spoofed URLs.

In any case, you cannot rely upon the data being received and you must validate on the server regardless of whether you included validation in your pages.
[ October 01, 2004: Message edited by: Bear Bibeault ]
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Thanks a lot for pointing it out. I too understand that the server should validate the info. I wasn't considering the point of spoofing and other security threats. Any way, shall keep in mind.

And
It is better to do all possible validations in the client and pass only the appropriate parameters to the server...so that u get the expected results.


I was in no way contradicting you......by any means.

Cheers,
Swamy

I mentioned the validations like fields being empty, or numeric validatios sortof things.

I do know that the server will and must always,always validate the correctness of the informatio.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!