Formatting Raw Data

We are currently using regular expressions to validate input. Can they also be used to format data read from a database?

For example, a phone number stored in a table as 1234567890 should be displayed as (123) 456-7890 on screen.

Can the same regular expression used to validate the input be used to format the output?

[337 byte] By [TomFrantza] at [2007-11-26 13:46:28]
# 1
Hi There,Yes you can. Once you get the Raw Data, does not matter where it is comming from, now it is yours and you can do anything you want with it.Database is just a storage place and adds nothing to data. Regards,Nosh
Nosha at 2007-7-8 1:21:36 > top of Java-index,Java Essentials,Java Programming...
# 2

> Yes you can. Once you get the Raw Data, does not

> matter where it is comming from, now it is yours and

> you can do anything you want with it.

> Database is just a storage place and adds nothing to

> data.

And what does that have to do with the average price of a Cambodian hooker? Much less with the @OP's question.

@OP, Take a look at the NumberFormat class, or even something as simple as StringBuilder.insert(). Regexp's probably aren't the best way to do this.

Message was edited by:

bckrispi

bckrispia at 2007-7-8 1:21:36 > top of Java-index,Java Essentials,Java Programming...
# 3
Regexp definitely are not the way to do this. Particularly if you have a well regulated field as per the example, it is much faster and easier to just use a substring().
jschella at 2007-7-8 1:21:36 > top of Java-index,Java Essentials,Java Programming...