Saturday, 15 May 2010

jquery.validate plugin - how to trim values before form validation -


I'm using excellent by Jenner Jeffer and I was wondering if there is an easy way to make that form element Automatically valid before trimming?

The following is a cut off, but the work example of a form that confirms the email address:

   & Lt; Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script src = "http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ () Valid (work () {$ ("# comment form"). Validate ({Rule: {email: {required: true, email: true}}})}}   gt; body & gt; form class = "cmxform" id = "commentForm" method = "get" action = "" & gt; & gt; label for = "cemail" & gt; ; E-mail: & lt; / label & gt; input id = "cemail" name = "email" class = "required email" /> & lt; input class = "submit" type = " Submit "value =" submit "/>  gt; & gt; & lt; / html & gt;  

problem That's why some users are getting confused Because they accidently enter some white space in their email address, eg "Test@test.com" and the form will not be submitted and there will be an error message: "Please enter a valid email address." It is not how whots are given space and they can get out of the site instead of trying to work.

Anyway, I was hoping that the series " JQuery.trim ( Value) "Whitspace before legalization There never has been deleted and validation error?

I can use to create my own email verification work but I'm sure there is a more elegant solution?

I have done this with success.

Instead:

  email: {required: true, email: true}  

I did this:

  email: {required: {dependent: function () {$ (this) .val ($ .trim ($ (this) .val ())); Back true; }}, Email: true}  

No comments:

Post a Comment