This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes should not contain any  special characters Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "should not contain any  special characters" Watch "should not contain any  special characters" New topic
Author

should not contain any special characters

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

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 ?


Save India From Corruption - Anna Hazare.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Nov 22, 2004
Posts: 124
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

Joined: Feb 22, 2005
Posts: 12
boolean matches= name.matches("!#@$%^]*");

dont use captical for variables, in your case use Name as name.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Feb 22, 2005
Posts: 12

if ( name.matches("[a-zA-Z]") ) {
// OK
}
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks a lot
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: should not contain any special characters
 
Similar Threads
password in struts
Java : How to accomodate special characters in the filename while uploading and downloading the file
how to avoid entering special characters
Regex for allowing alpha characters and wildcard %
Relative File Paths