Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using addMethod with validator

 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the zero on the server!

Eric
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm with Eric. Adding the zero on the client is not a good idea. Do it on the server.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. Two respected authorities have said "don't do that", so server-side it is.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic