473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to Validate Creditcard number in Textbox

Hi,
I have created a Textbox for my credit card number entry for my payment webpage. Can anyone help me in telling me the codes of how to make sure 16 digits of the number is entered . Methods such as count or something which i completely forgot?!

Thank you so much.Any advise is appreciated deeply.
Feb 10 '09 #1
4 2461
PRR
750 Expert 512MB
googlin i found this
Expand|Select|Wrap|Line Numbers
  1. public static bool validCCNum(string num)
  2. {
  3.     // This expression is looking for a series of numbers, which follow the pattern 
  4.     // for Visa, MC, Discover and American Express. It also allows for dashes between sets of numbers
  5.     string pattern = @"^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$";
  6.     Regex match = new Regex(pattern);
  7.     return match.IsMatch(num);
  8. }
  9. link
  10.  
depending on the credit card you are accepting you will have to modify or possible use switch statement for validation...along with regular expression
link
Feb 10 '09 #2
Frinavale
9,735 Expert Mod 8TB
The JavaScript String Object has a length method that returns the length of a string.


Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <script type="text/javascript">
  5. function ShowLength(){
  6.    var txt= document.getElementById("myTextBox").value;
  7.    alert(txt.length);
  8. }
  9. </script>
  10.  
  11. <input type="text" id="myTextBox" value="Hello World!" />
  12. <br />
  13. <input type="submit" onclick="ShowLength();" value="Show Length" />
  14. </body>
  15. </html>
Feb 10 '09 #3
Wow~ very useful. Thank you so much ~ Very appreciate the effort . ^_^
Feb 10 '09 #4
PRR
750 Expert 512MB
Welcome, do continue to post on Bytes again some time.
Feb 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: simonmarkjones | last post by:
I want to validate my form using a BeforeUpdate event. However now that i call my code with a beforeupdate it wont let me go to next or previous records. What code should i put in o allow me...
3
by: Poppy | last post by:
I have a text field I want to validate. It needs to store a number e.g "23.5", "10000" Is there any isnum() method in .net. TIA
11
by: wolf | last post by:
There are three webcontrol on my asp.net form: a TextBox, a submit button and a RegularExpressionValidator. And I had set ControlToValidate property of the RegularExpressionValidator to the...
1
by: antonyliu2002 | last post by:
Suppose that I have the following on my web: Your annual income: o > o < ___________ If the user enters a number in the textbox indicated by the underline, but forget to click either of...
9
by: B-Dog | last post by:
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say...
3
by: Jeff Jarrell | last post by:
I have one textbox on a form. Nothing else. The validate event doesn't fire. Drop another textbox on the form and the validate event fires. Set tabstop = false on the 2nd text box and the...
3
Atli
by: Atli | last post by:
Hi o/ Im making a online shop where I'd like my customerst to pay with a creditcard. I don't really know how to do this, but I've imagined that it might somehow charge the card and return if it...
1
by: yegeswari | last post by:
Hi, How to validate given textbox value is number only. Suppose given text value is other than number mean it should give an alert message. Thanks and regards, Yegeswari
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.