how to validate a control character in server side ?

Hi All,

I am working with a Address page where I want to restrict the user to enter from control characters, ie (1-31) & above 127 ascii characters.

when ever I tried to enter a character like (♫,☺), it converts to a decimal format (♫,.....) in my action class.

I am trying to validate by using regular expression (/&#\\d+;/), is it right way ? also when ever an control character found control moves back to jsp page but in jsp page I can't see the control character anymore, it displayes as(♫,....).

is there a way to convert this decimal values to symbols one it returns to jsp page.?

Please help me in this. I really spent a lot on this, still not getting a solution.

-bp

[755 byte] By [Balmiki-Pradhanaa] at [2007-11-27 11:05:45]
# 1

Here's an idea;

On your JSP page, change your submit button to a regular button that calls a javascript function via onClick event. In that function, verify there is no bad ascii characters. If so, pop up a dialog box warning that he has bad ascii characters and dont submit. If all is ok, submit the form via something like this:

document.myFormName.submit();

I believe javascript supports regularExpression to check for ascii characters, but you'll have to research that in javascript. I'm not familiar enough with regular expressions to help you out. If you cant find such a function, you can go though each characer in the string one by one instead. Just be sure you also check for characters html has a problem with such as <,>,&, etc.

Back on the server, its normal practice to re-verify everything coming from the JSP page to ensure the GUI developer of the JSP didnt make a mistake on verification and let something get though that your server side business logic didn't expect. You can also use regular expressions there if you want for verification.

George123a at 2007-7-29 13:10:47 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi All,

I am working with a Address page where I want to restrict the user to enter from control characters, ie (1-31) & above 127 ascii characters.

when ever I tried to enter a character like (♫,☺), it converts to a decimal format (& # 9792;,.....) in my action class.

I am trying to validate by using regular expression (/&#\\d+;/), is it right way ? also when ever an control character found control moves back to jsp page but in jsp page I can't see the control character anymore, it displayes as(& # 9792;,....).

is there a way to convert this decimal values to symbols one it returns to jsp page.?

Please help me in this. I really spent a lot on this, still not getting a solution.

-bp

Balmiki-Pradhanaa at 2007-7-29 13:10:47 > top of Java-index,Java Essentials,Java Programming...
# 3

I want only server side validation, not client side...☺

Balmiki-Pradhanaa at 2007-7-29 13:10:47 > top of Java-index,Java Essentials,Java Programming...
# 4

> I want only server side validation, not client

> side...☺

That's a bad design decision in my opinion, but to do it in java, you can loop over each character and examine it's int value. If it's out of range, reject it.

for each char c in the String {

if (int)c > 127 or (int)c < 32 {

reject

}

}

When your users enter data into your app, they should be given immediate feedback when they enter invalid data. They shouldn't have to wait until they submit and get an error page to find out their data was rejected, and no one wants to have to reenter data because of a mistake they didn't know they were making.

hunter9000a at 2007-7-29 13:10:47 > top of Java-index,Java Essentials,Java Programming...