wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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

Joined: Dec 16, 2010
Posts: 826

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.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Eric Pascarello

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

J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 826

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: 60765

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

Joined: Dec 16, 2010
Posts: 826

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

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