assets/scripts/coffee/hoarder/validator/constraints/credit_card_constraint.coffee in hoarder-js-0.0.1 vs assets/scripts/coffee/hoarder/validator/constraints/credit_card_constraint.coffee in hoarder-js-0.0.2

- old
+ new

@@ -1,18 +1,12 @@ -ValidationError = require "hoarder/validator/error/validation_error" +BaseConstraint = require 'hoarder/validator/constraints/base_constraint' -# -# @author - Tim Shelburne <tim@musiconelive.com> -# -# -# -class CreditCardConstraint - canHandle: (type)-> - type is "creditCard" +class CreditCardConstraint extends BaseConstraint - handle: (element)-> - if element.value.match(/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/) - return [] - else - return [ new ValidationError "Please enter a valid credit card number." ] + constructor: -> + @type = "creditCard" + + rulePasses: (element)-> element.value.match(/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/) + + errorMessage: -> "Please enter a valid credit card number." return CreditCardConstraint \ No newline at end of file