views:

50

answers:

2

Hi,

I am new at this so be easy on me... :)

  1. I need to validate if a the ID number that the user typed in my site is a valid ID.

How do I check it?

Do I need to use RegularExpressionValidator?

  1. More over, I also need to validate the credit card number, I found a few RegularExpressions for that in the net but each one is different from the other and I am not sure which one to use.. Does anyone know od a working expression that will suit all credit cards??

Thanks, Tsil.

+1  A: 

You never need to use the RegexValidator, it's just handy sometimes.
EDIT: a Regex can only check for a string-pattern and can't do any calculations or other checks that require numbers as opposed to "sequences of digits".

It all depends on what you consider a valid "ID". Is any number "valid" or are there more rules?

For a creditcard number you also need to specify what you consider valid: just a number of digits (12 I think?) with maybe added dots or spaces? Or do you want to know whether that card itself is valid? That's a different problem entirely!

EDIT: for a SSN, see wikipedia.

Hans Kesting
I am talking about Social security number,
tsil
I know there is an algorithm to calculate that but I cn't find it and not sure how to use it...
tsil
regarding the Credit card, I want to make sure that the card number is reall and no one made it up.
tsil
A: 

What kind of ID are you talking about? A social security number or a User ID to login?

Since you are talking about it in the context of a Credit card and Regular Expression validators, I will assume that you are talking about a Social Security number.

Anyways, if you Are talking about Login controls or such please go here.

Regarding Social Security number, this depends on what country the person is from and how the individual country sets up their numbers, but to give you a little taste of what you might want to do, check out How to use Regulat Expression Validators.

However, Please, please, please do not validate the credit card number yourself. There are Bank Services that you can use for this, head over to PayPal and check their API for C#, this will most certainly make your users feel more comfortable on your site.

Also use SSL.

Regular expression validator example

<%@ language="C#" %>
<form id="form1" runat="server">
    <asp:TextBox ID="txtName" runat="server"/>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
    <asp:RegularExpressionValidator ID="regexpName" runat="server"     
                                    ErrorMessage="This expression does not validate." 
                                    ControlToValidate="txtName"     
                                    ValidationExpression="^[a-zA-Z'.\s]{1,40}$" />
</form>

If you want to try out some regular expressions head over to the greatest resource there is. And don't forget to read this.

You might also want to read User Input validation in ASP.NET from msdn and Learn ASP.NET from Microsoft has some great videos on ASP.NET Security that you might find usefull.

Filip Ekberg