jquery regex validation does not properly validate credit card field -
I have a form with many fields, I'm using a forked jQuery validation because I have a font-awesome check I am using exclamation points beside markings and valid fields. Apparently jQuery validation does not allow you to add more than one category to an element. However, all of my fields are being validated, except for my credit card verification. I have simple regex ( HTML jQuery I keep it up, but for some reason it will not be compiled there. resolve I think you should The approach should be changed to achieve the desired. If I were you, then I would make a new rule: Try removing the rule Also, look for the standart Why does your code not work If you use the Each rule can be specified as being dependent-property to implement the rule only in certain conditions. It is simple Ask me if something is not clear to you. Hope, it will help you. / ^ \ d {16} $ / to check for 16 digits). My code is not working right now.
& lt; form id = "checkout_form" method = "post" action = "" & gt; Card number: & lt; input id = "credit_card_card_number" name = "credit_card [card_number]" size = "30" type = "text" /> gt; & Lt; i class = "fa fa-lg" & gt; & Lt; / I & gt; & Lt; Input type = "submit" & gt;
$ (document) .ready (function () {$ ('# checkout_form'). ({Rule: {'credit_card [card_number]': {required: {depends: function: element} {var regex = / ^ \ d {16} $ /; recharge regex test (element.value);}} }}, Valid class: "FA-check", error class: "FA-exclamation-triangle", error placement: function (error, element) {}, highlight: function (element, error class, legal class) {$ ( Element) .next (.) AddClass (ErrorClass) .removeClass (validClass);}, unhighlight: function (element, error Class, valid class) {$ (element) .next (). RemoveClass (errorClass) .addClass (valid class);}});});
$ Validate.Adit Method ("Legal Credit Card", Work (Value, Element) {return.optional (element) ||/ ^ \ d {16} $ / Tate (value)}, "Use a valid credit card number. "); After that, you just have to use the new rule, such as standart
required rule:
rule: {credit_card [
legalCreditCard: true to see the difference.
credit card method in the jQuery validation plugin:
dependent position it is wrong. See this:
Validate $ ("selector") ({Rule: {Contact: {Required: True, Email: {Depends}: Work (Element) {Return $ ("#contactform_email: checked")}}}}});
Comments
Post a Comment