Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

should not contain any special characters

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please help as how to proceed ?

I am performing a server side validation , and the Name should not contain any special characters like !#@$%^&*()-+ . except alphabets .

What should be the coding part i should set inside the setter methods of a DTO


Is it appropiate to put this logic inside a Setter Method ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't (though I would change the Name property to comply with standard variable naming conventions). A DTO should be nothing more than a transport mechanism.

I'd use a validation framework or some sort of rules engine in the code that implements my business logic.
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1. You can do the validation in the client side.
2. You can do the validation(business) in the server side within servlet

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Inayath wrote:Hi,

1. You can do the validation in the client side.



Of course all this can be is a guide, since there is no way to guarentee validation is run client side in a normal web application. If validation is important (and it usually is) then the server is the place to be doing it.
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange..!

If I have to do a sanity check, like for example lenght check, null check or in this case character check.
I have to post a request from the client to server if its invalid then again post the request with a change.

Will it not be feasible to have basic sanity check on the client side and have a pure business check validation at the server side.
 
karan wadhwani
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boolean matches= name.matches("!#@$%^]*");

dont use captical for variables, in your case use Name as name.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Inayath wrote:Strange..!

If I have to do a sanity check, like for example lenght check, null check or in this case character check.
I have to post a request from the client to server if its invalid then again post the request with a change.

Will it not be feasible to have basic sanity check on the client side and have a pure business check validation at the server side.


Yes it will be feasable and probably quite a helpful thing to do. My point is you cannot rely on client side validation alone, because you can't guarentee it is being run.
 
karan wadhwani
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

if ( name.matches("[a-zA-Z]") ) {
// OK
}
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic