File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes using addMethod with validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "using addMethod with validator" Watch "using addMethod with validator" New topic

using addMethod with validator

J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632

I have several form fields that require a number. The jQuery validator plugin has a number rule that does not except numbers that start with a decimal point; they must start with zero. I found this code which allows the number rule to accept numbers without a leading zero.

My problem is, I still need a leading zero added to the number before I attempt to insert it into the database. How would I go about adding a leading zero (on the blur event) to those fields that start with a decimal point? I'd like to do it within the above method so I don't have to bind a function to the blur event on every single number field.

"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
Add the zero on the server!

J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632

Eric Pascarello wrote:Add the zero on the server!

Yes, I'll be checking that in the validation class that's next on the list, but I'd like to modify the input fields for the sake of "user experience". It's not critical to the app, but it's something that I'd like to learn.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60050

I'm with Eric. Adding the zero on the client is not a good idea. Do it on the server.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632

Okay. Two respected authorities have said "don't do that", so server-side it is.

I agree. Here's the link:
subject: using addMethod with validator
Similar Threads
Form Validation
Regular Expression Help
Accessing struts Bean property in javascript
How work this reusable form validation script
rich:ajaxValidator problem