aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Regular Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Regular Expression" Watch "Regular Expression" New topic
Author

Regular Expression

Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,all

In Database Schema part of instructions file,there are two fields "rate" and "date" with specialized format.

Should I use regular expression to limit format of the strings?
Would you please explain that?

Thanks


Regards, Richard
No�l Verdurmen
Ranch Hand

Joined: Jul 28, 2004
Posts: 33
Originally posted by Richard Jackson:

In Database Schema part of instructions file,there are two fields "rate" and "date" with specialized format.

Should I use regular expression to limit format of the strings?
Would you please explain that?


Can you edit these fields somewhere in your application? If you can, it would be useful to use regular expressions to prevent users from entering strings in invalid formats. However, in my application the user is not
allowed to enter values for "rate" or for "date", so there is no reason to use regular expressions.


No�l
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
Originally posted by Richard Jackson:
Hi,all

In Database Schema part of instructions file,there are two fields "rate" and "date" with specialized format.

Should I use regular expression to limit format of the strings?
Would you please explain that?

Thanks


Actually there is a third field, "owner" or "customer" that has a restricted format, and the user does get to type this in.
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
For URLyBird, but probably covers all NX

Owner (customer) field [input case]:
use: book a room against

This is entered in someway by the user and must be of some specific format, however you interpret the spec. Personally I've gone for '[0-9]{8}'.
This should be validated on entry and IMO should be validated in your business tier to strictly adhere to your chosen format. It should then be validated a final time by the database but only so that it adheres to max field length. So 3 validations in all. My first validation is not really a validation at all since the user is forced to enter the correct format.

Date field [output case]:
use: check 48hr rule

This is not entered by user but it is used and it must be in a format as specified, or rather it is reasonable to expect it to be in that format. Whoever entered it is responsible for validation, but we must deal with the case where it is bad format. Personally I parse the date with a SimpleDataFormat if it throws exception my isRoomBookable returns false, but the exception is logged.

All IMHO of course


SCJP 1.4, SCJD
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Originally posted by mike acre:
For URLyBird, but probably covers all NX

Owner (customer) field [input case]:
use: book a room against

This is entered in someway by the user and must be of some specific format, however you interpret the spec. Personally I've gone for '[0-9]{8}'.
This should be validated on entry and IMO should be validated in your business tier to strictly adhere to your chosen format. It should then be validated a final time by the database but only so that it adheres to max field length. So 3 validations in all. My first validation is not really a validation at all since the user is forced to enter the correct format.

Date field [output case]:
use: check 48hr rule

This is not entered by user but it is used and it must be in a format as specified, or rather it is reasonable to expect it to be in that format. Whoever entered it is responsible for validation, but we must deal with the case where it is bad format. Personally I parse the date with a SimpleDataFormat if it throws exception my isRoomBookable returns false, but the exception is logged.

All IMHO of course



I got the same thing, except I got field validations in client logic, and record validation in business logic, and data validation in schema logic.

And since I can't export the schema to the client (alas) a lot is restricted.


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,all

Like Noel said,
Can you edit these fields somewhere in your application? If you can, it would be useful to use regular expressions to prevent users from entering strings in invalid formats. However, in my application the user is not allowed to enter values for "rate" or for "date", so there is no reason to use regular expressions.


If I do not have any edit operations,do I never need to use "regular expressions" to limit each field format?

That also implys that I only consider String format for all fields while I do read /write /update /delete action, doesn't that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular Expression