Bug Tracker

Opened 10 years ago

Closed 10 years ago

#2694 closed bug (fixed)

[validate] creditcard validates true if alpa characters are used

Reported by: jforth Owned by:
Priority: major Milestone: 1.2.4
Component: plugin Version: 1.2.3
Keywords: validate creditcard Cc:
Blocked by: Blocking:

Description

creditcard rule validates true if alpa characters are used

example: asdf validates true.

Change History (3)

comment:1 Changed 10 years ago by jforth

fix? maybe

		creditcard: function(value, element) {
			
			if ( this.optional(element) )
				return "dependency-mismatch";
			
			if(value.match(/\D/)) return 0;
			
			var nCheck = 0,
				nDigit = 0,
				bEven = false;

			value = value.replace(/\D/g, "");

			for (n = value.length - 1; n >= 0; n--) {
				var cDigit = value.charAt(n);
				var nDigit = parseInt(cDigit, 10);
				if (bEven) {
					if ((nDigit *= 2) > 9)
						nDigit -= 9;
				}
				nCheck += nDigit;
				bEven = !bEven;
			}

			return (nCheck % 10) == 0;
		}

comment:2 Changed 10 years ago by jforth

		creditcard: function(value, element) {
		    
    		if(/[^0-9-]+/.test(value)) return 0;
			
			if ( this.optional(element) )
				return "dependency-mismatch";
					
			var nCheck = 0,
				nDigit = 0,
				bEven = false;

			value = value.replace(/\D/g, "");

			for (n = value.length - 1; n >= 0; n--) {
				var cDigit = value.charAt(n);
				var nDigit = parseInt(cDigit, 10);
				if (bEven) {
					if ((nDigit *= 2) > 9)
						nDigit -= 9;
				}
				nCheck += nDigit;
				bEven = !bEven;
			}

			return (nCheck % 10) == 0;
		}

comment:3 Changed 10 years ago by joern

Resolution: fixed
Status: newclosed

Fixed in [5340].

Note: See TracTickets for help on using tickets.