This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes regular expression for field validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "regular expression for field validation" Watch "regular expression for field validation" New topic
Author

regular expression for field validation

Rachel Kumar
Ranch Hand

Joined: Oct 21, 2008
Posts: 51
i have a text field that needs to accept on;y integers and not more than 10 digits.

i wrote the below code and it accepts the integers but when i eneter more than 10 digits it evaluates to some junk value and when i enter letters it gives error page..

Pattern p= Pattern.compile("([0-9]*)");
String likeExpression = "%" + this.id + "%";
Matcher m =p.matcher(likeExpression);
if(m.lookingAt()){
results =orderdao.findWithLikeId( likeExpression );
logger.debug("m.lookingAt {}", m.lookingAt());
logger.debug("results {}", results.size() );
return Action.SUCCESS;


please can i get help, its a bit urgent
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If the "id" is an integer then you're getting an overflow error. This is trivially verifiable by entering numbers less-than, and greater-than, 2^32. This is not technically a Struts issue, although you may need to change the way you're getting the ID from the form, because:

Your regular expression is incorrect and will not do anything related to checking for a 10-digit number, your regular expression checks for percent signs surrounding a series of digits of arbitrary length. Searching the web for Java regular expressions should help you. Your pattern matcher shouldn't also include the SQL syntax.

So it's pretty much wrong all over
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regular expression for field validation
 
Similar Threads
float or double
JFormattedTextField with 6 integers and 2 decimals
Decimal precision and scale
number formatting????
Rounding Error in a calculateLitresPer100Km method - read on for more details