Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    Credit Card Validation

    Does anyone know of any credit card validation scripts that include validation for switch/maestro?
    I found a great script but its very americanised so no good for my purposes

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Raleigh, NC
    Posts
    484
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I may not be helping since I don't know that switch/maestro is but this is the only one I've used in the past...

    http://javascript.internet.com/forms...edit-card.html
    -WebMark Art
    Programming is 80% thinking and 20% spelling

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Thats similar to the one I've found (but in asp not javascript) but it doesnt handle switch cards. I think I might have got it sussed with a little regex... I'm pretty sure all switch numbers start 67
    Code:
    ^((67\d{2})|(4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$
    that handles visa, mastercard, switch, solo, and amex I think

  • #4
    New to the CF scene
    Join Date
    Aug 2005
    Location
    Charlotte, NC
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I do not know of any good prewritten/free scripts available on the web. Maybe some digging on google can produce some results. However, if you want to write your own... read below.

    Are you just checking to see if the value is numeric and if the number's prefix is assigned to a specific card type? (that appears to be what the regex is doing). However, something more robust may be used if you implement validation using the Luhn formula (mod 10). Not sure about switch/solo but visa/mastercard/amex and most other credit card numbers can be checked in this fashion.

    Luhn Formula -- http://www.webopedia.com/TERM/L/Luhn_formula.html

    Also, it may be good to mention that before you pass the number to the above mentioned check it will be wise to check the length and make sure it is correct for the card type trying to be submitted.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •