Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

number validation using validator

 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

In a form, i should not allow the user to type any characters other than numbers.

Currently i am using struts 1.1 Validator, which is showing error on submission only.

Thanks in advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts validation is designed to be invoked only when a form is submitted. If you want something other than that, you will have to write it yourself in javaScript.
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Merrill

Thanks for ur reply.......I go for Javascript

One more small doubt???

I want to validate a username on registration,

Name should start with character and not a number,but number can present except as a first character..........

For this too i want to go for javascript OR any other way to do in struts validator itself
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can accomplish this with the match() string function in javaScript along with a regular expression (regex).

If you're not familiar with regular expressions, here's a link to learn how to use them:

http://www.regular-expressions.info/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic