• 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

Validation in JSP.

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a form with 3 fields in a form, UserName, City, Country. Length of each field should not exceed 10 characters. If it exceeds it, the page should be reloaded with error message on the same line of the text box.

Can anybody tell me how I can do it?
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<input type="text" maxlength="10" name="text1">

User maxlenght attribute, it will not allow user to enter 11th character at first place.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless a malicious user writes his own form to submit to your server.

Point is, client-side validation should never be trusted.

Yes, go ahead and add the maxlength attribute -- that's good for users since they cannot enter too many characters. But also check the length when the code is submitted.

In fact, validation should occur at every layer in the app in case someone is trying to spoof the upper layers. It also makes your code more robust and re-usable.
 
reply
    Bookmark Topic Watch Topic
  • New Topic