• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular expression in a jsp tag

 
Sandeep Kumar B
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I need to pass a regular expression with the data so that I get the returned data in required format as per regex passed

1. Pass the regex 1 and the 10-digit phone number(for instance 1234221556) and the output should be 123-422-1556
2. Pass the regex 2 and a given string if less than 20 digits will have 0 prefixed so that length of resulting string = 20
3. Pass the regex 3 and a number 543.22 and the output is $543.22

How to accomplish this?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regular expressions aren't used for formatting, but for pattern matching, so you're on the wrong track.

What you want to do can most likely already be accomplished with the tags of the JSTL fmt tag set.
 
Sandeep Kumar B
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Is there way to give a string as input and depending on its length append sufficient zeros to make it length 20
For instance.....abc2245671213999 gets converted to 0000abc2245671213999
Right now I am doing the same thing using my own custom tag by using doStartTagInternal
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35743
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a formatNumber tag. But you don't have a number, that wouldn't work. You'd need a custom tag. Or a Java method in the bean containing the data.
 
Sandeep Kumar B
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I thought the same that formatNumber won't work for even phone numbers

Can I just give the format as a paramter (###-####-#### OR ##-####-####) and the numbers gets converted to appropriate format?
1234221556 gets converted to 123-422-1556 and 12-3422-1556
How to accomplish this?

I guess the in built date format works the same way
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!