shanuragu
06-16-2003, 10:22 AM
Hi
Please tell me how to validate a credit card number.
ShaRa
Please tell me how to validate a credit card number.
ShaRa
|
Click to See Complete Forum and Search --> : Credit Card Number Validation shanuragu 06-16-2003, 10:22 AM Hi Please tell me how to validate a credit card number. ShaRa Jona 06-16-2003, 11:14 AM It depends how you process it. Do you want it to be xxxx-xxxx-xxxx-xxxx (where x can be any number)? Or do you want it to be xxxx xxxx xxxx xxxx with spaces instead of dashes? For dashes or spaces, the below is what you would use: <script type="text/javascript"> function process(obj){ var re = /^\d{4}(-|\s)\d{4}(-|\s)\d{4}(-|\s)\d{4}$/ if(re.test(obj)){ //process form } else { alert("Please enter a valid credit card number"); return false; } } </script></head> <body> <form name="myFormName" onsubmit="return process(this.yourTextBox.value);"><div> <input type="text" name="yourTextBox"> <input type="submit"> </div></form></body> Jona jeffmott 06-16-2003, 12:51 PM /^\d{4}(-|\s)\d{4}(-|\s)\d{4}(-|\s)\d{4}$/This also allows any combination of the two. e.g., xxxx xxxx-xxxx xxxx. Line breaks and tabs are also passed (this may or may not have been desired, I'm not sure)./^\d{4}([- ])\d{4}\1\d{4}\1\d{4}$/ Jona 06-16-2003, 12:52 PM Originally posted by jeffmott This also allows any combination of the two. e.g., xxxx xxxx-xxxx xxxx. I know. I wasn't sure what he/she wanted, so I just did either/or until he/she replies... If that is, he/she replies. ;) (What are you on some kind of humiliation spree today? :rolleyes: ) Jona :D jeffmott 06-16-2003, 12:59 PM Yeah, the one I posted allows either/or, just not mixed. Not meaning to harp on you either :rolleyes: You're replied to so many threads, it'd be difficult to avoid you. :p Jona 06-16-2003, 01:03 PM 'Twas a joke, my friend. ;) I know you weren't harping on me, you're trying to better help the individual who posted; me, I'm still learning a bit of the RegExp stuff. :rolleyes: But I think I'm doing okay for now. :) Jona AdamGundry 06-17-2003, 07:30 AM You might find this WebReference article useful: http://www.webreference.com/programming/carts/chap7/3/index.html Adam webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |