Click here to Skip to main content
15,891,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I need to validate New jersey Taxpayer Identification Number

The length of this control 12 digits.

The validation scenarios:

This control contains only 12 digits.

all 12 digits are not same.
Ex: 111111111111
..
999999999999
it should not be sequence order
like 123456789012

It should not contain last three digits are zeroes
like 543044885000

I need one regular expression for all the above scenarios.

Thanks' in advance.


--
Best Regards
Ranganth potluri
Posted
Updated 14-Jun-13 2:29am
v2
Comments
Have you tried anything yet?

I won't use regular expression for that: you might specify the regular expression for matching just the 12 digits then you may easily check all the other conditions in code.
 
Share this answer
 
Comments
Thanks7872 14-Jun-13 8:48am    
Good one.↑voted.Elaborated lil bit in my answer.
Excatly as per the suggestion from CPallini above,you should check for just 12 digits.For reference see below link

JavaScript :Phone Number validation[^]

For other scenarios,you can use something like below

string temp="eranganath";


now temp[0] would give you 'e'.Just like this you can compare your strings in coding.

This is just example to show you how to go ahead.

Regards.. :laugh:
 
Share this answer
 
v2
C#
static void Main(string[] args)
        {
            string[] ids = new string[]

       {

          "111111111111",

          "999999999999",

          "123456789012",

          "456789012345",

          "543044885000",

          "124689124000",

          "317238921101",

          "772190300023"

       };




            string repeat = @"(?!(\d)\1+$)";

            string sequence = @"(?!(012345678901|123456789012|234567890123|" +

                                   "345678901234|456789012345|567890123456|" +

                                   "678901234567|789012345678|890123456789|" +

                                   "901234567890)$)";

            string zeros = @"(?!\d{9}000$)";

            string digits = @"\d{12}";




            string regExp = String.Format(@"^{0}{1}{2}{3}$", repeat, sequence, zeros, digits);




            foreach (string id in ids)
            {

                Console.WriteLine(Regex.IsMatch(id, regExp));

            }




            Console.ReadKey();
        }


This code is working for c#. when we are coming to java script it is not working.

regular expression in c#.
string regExp ="^(?!(\d)\1+$)(?!(012345678901|123456789012|234567890123|345678901234|456789012345|567890123456|678901234567|789012345678|890123456789|901234567890)$)(?!\d{9}000$)\d{12}$"


Somebody help me how to convert this into JavaScript.

Thanks in advance.

Regards,
Ranganath Potluri
 
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