javascript - How to validate email with jQuery Validate plugin -
In some cases, jQuery is not perfect for email verification. "Abc@test.c" (single letter suffix) and "중국어 @ test.com" (non alpha-numerical) are passed as valid email addresses.
How can I use these two invalid email addresses in the jQuery validated plugin?
, you will need to create your own custom method.
Add a custom verification method. It should have a name (must be a valid JavaScript identifier), a JavaScript-based function and a default string message.
Argument:
Names; String method is used to name, identify and reference, should be a valid JavaScript identifier
method; Callback actual method implementation, if any element is valid then true. First argument: current value second argument: valid element third argument: parameter
Message (optional); The default message for displaying the string, the function for this method There may be a function created by JQuery.validator.format (value). When the undefined, pre-existing message is used (easy to localize), otherwise the field-specific message must be defined.
The following is a custom method
which I have named newemail
. Right now, it is just using the default function for "email" verification just edit the regex in this function corresponding to your particular requirements.
jQuery.validator.addMethod ("newmail", function (value, element) {// contributed by Scott Gonzalez: http: // Projects.scottsplayground.com/email_address_validation/ this return.optional (element) || / ^ ((([az] | \ d | [! # \ $% & Amp; * \ + \ - \ / = \ \ ^ _ `?.. {\ |} ~] | [\ U00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]) + (\ [[az] | \ d | [# \ $% &?!? \ * \ + \ - \ / = \ \ ^ _ `{\ |} |] | [\ u00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]) +) *) | ((\ X22) ( (((\ X20 | x09) * (\ x0d \ x0a)) (\ x20 |? \ X09) +)? (([\ X01- \ x08 \ x0b \ x0c \ x0e- \ x1f \ x7f] | X21 | [\ x23- \ x5b] | [\ x5d- \ x7e] | [\ u00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]) | (\ \ ([\ x01- \ x09 \ x0b \ X0c \ x0d- \ x7f] | [\ u00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF])) * * (((xx20 | x09) * (\ x0d \ x0a)) ( \ X20 | | \ x09) +) (\ X22)) @ (([[az] |? \ D | [\ u00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]) | (([az ] | \ D | [\ U00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]) ([az] | \ d | - |. \ | _ | ~ | [\ U00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]) * ([az] | \ d | [\ u00 A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]))) \) + (([az] |. [\ U00A0- \ uD7FF \ UF900- \ uFDCF \ uFDF0- \ uFFEF]) | (([az] | [\ u00A0- \ uD7FF \ uF900- \ uFDCF \ uFDF0- \ uFFEF]) ([az] | \ d | - |. \ | _ | ~ | [\ U00A0- \ Ud7FF \ Ufar900- \ Ufdsf \ Ufdf0- \ Ufarfafa]) * ([today] | [\ U00A0- \ Ud7FF \ Ufar900- \ Ufdsf \ Ufdf0- \ Ufarfafa]))) $ / e .test (value); }, "Please enter a valid e-mail address");
Use the inside then it .validate ()
as you would use any other rule.
Rules: {InputName: {required: true, Nyamel: true}}
Comments
Post a Comment