aspose file tools*
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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "using addMethod with validator" Watch "using addMethod with validator" New topic
Author

using addMethod with validator

J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 963
    
  13

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
author
Rancher

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

Eric
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 963
    
  13

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
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

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
Bartender

Joined: Dec 16, 2010
Posts: 963
    
  13

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

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using addMethod with validator