Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to validate ID number and cell number in asp.net? i am trying to register users to the system, so i need to check if the ID number is valid. for instance we have 13 digits for id number in South Africa (meaning year first, month second, day in which u were born[meaning 750910- means you were born in 1975 september on the tenth day]) and ten digits for a cell number.
Posted
Updated 7-Aug-12 5:44am
v2
Comments
[no name] 7-Aug-12 11:32am    
If you really expect an answer to your quesiton, you are going to have to come up with more information than that. Like what it is that you are trying to do for instance.
ZurdoDev 7-Aug-12 12:13pm    
You can use regular expressions, javascript, C#, SQL, etc. You can do client side validation, web service, or in C# postback. It's up to you. But this question is really so vague we can't tell you exactly what to do.
Sergey Alexandrovich Kryukov 7-Aug-12 12:25pm    
What is "ID number"? Not ID itself, but its number? :-)
--SA
Xavi Giqwa 7-Aug-12 13:19pm    
identity document number
Sergey Alexandrovich Kryukov 7-Aug-12 14:51pm    
:-)

this is how i solved it

C#
//call validation method
if (validate_SA_ID(txtIdNumber.Text) == true)
{
//taking user iput code

}
else if (validate_SA_ID(txtIdNumber.Text) == false)
{
//error msg

}

// validation method
 private bool validate_SA_ID(string id_num)
        {

            if (id_num == "0000000000000")
            {
                return false;
            }
            bool IsValid = false;
            if (id_num.Length == 13)
            {
                int c, odds, result1, result2, result3, dsada;
                odds = 0;
                result2 = 0;
                string evens = "";
                for (c = 0; c < 12; c++)
                {
                    if (c % 2 == 0)
                        odds += Convert.ToInt32(id_num.Substring(c, 1));
                    else
                        evens += id_num.Substring(c, 1);
                }
                result1 = Convert.ToInt32(evens) * 2;
                string res = result1.ToString();
                int k;
                for (k = 0; k < res.Length; k++)
                {
                    result2 += Convert.ToInt32(res.Substring(k, 1));
                }
                result3 = odds + result2;
                dsada = 10 - result3 % 10;
                if (dsada.ToString().Length == 1)
                {
                    if (Convert.ToInt32(id_num.Substring(12)) == dsada)
                    {
                        IsValid = true;
                    }
                    else
                        IsValid = false;

                }
                else
                {
                    if (dsada.ToString().Substring(1, 1) == id_num.Substring(12, 1))
                    {
                        IsValid = true;
                    }
                    else
                    {
                        IsValid = false;

                    }
                }
            }
            return IsValid;

        }
 
Share this answer
 
Comments
Member 12679405 6-Apr-17 9:42am    
Nice one.

Please be careful...
- &qout;&qout;; represent "";
- &alt represent > operator

Thank you so much
Nobody force you to use Regex and nuthing else. First use Regex to make sure all characters are numbers (or apply some other criteria, as required), and then validate that the length of the string is the same as expected, using string.Length.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900