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 ( / ^ \ d {16} $ / to check for 16 digits). My code is not working right now.

HTML

  & 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;   

jQuery

  $ (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);}});});   

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:

  $ 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 [  

Try removing the rule legalCreditCard: true to see the difference.

Also, look for the standart credit card method in the jQuery validation plugin:

Why does your code not work

If you use the dependent position it is wrong. See this:

Each rule can be specified as being dependent-property to implement the rule only in certain conditions.

Validate $ ("selector") ({Rule: {Contact: {Required: True, Email: {Depends}: Work (Element) {Return $ ("#contactform_email: checked")}}}}});

It is simple

Ask me if something is not clear to you.

Hope, it will help you.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -