• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regular expression for field validation

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic