'How to validate tin and cst using PHP?

I need to validate India's Taxpayer Identification number(TIN) and Central Sales Tax(CST) fields. How can I do that using php?

I have to implement this validation in seller registration form in shopping cart.

php


Solution 1:[1]

You can use preg-match to achieve your results

as you have mentioned in your comments TIN is 33392964391 exactly 11 digits you can do it in the following way in PHP

function validateFieldByRegex($regex , $string)
{
    if ( !preg_match($regex, $string) ) {
        echo 'incorrect string';
    } else {
        echo 'correct string';
    }
}

validateFieldByRegex('/^[1-9]([0-9]{1,10}$)/', '33392964390');
validateFieldByRegex('/^[1-9]([0-9]{1,6}$)/', '1280154');

Solution 2:[2]

Indian TIN number consists of 11 digit numerals and will be unique throughout the country. First two characters will represent the State Code as used by the Union Ministry of Home Affairs.

RegEx -

^(3[0-5]|[012][0-9]|[1-9])\d{9}$

Matches starting with 01 to 35

Non-Matches starting with 0 or above 36

Check test cases here

Refer here

Solution 3:[3]

if you need to validate tin from India and other countries you could do it here

They have API that return response in json.

May be a goode solution if you need tin check for more countries. They perform for more than 100 countries.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shahbaz
Solution 2 Rohan Khude
Solution 3 N Martins