Validate IFSC and GSTIN in JavaScript
Catch bad bank and GST numbers before they hit your backend, with a regex pre-check and a free validation API.
By the apibharat.com team ยท
Why validate on the client and the server
Bank and tax numbers have strict, well-known formats. A quick regex check in the browser catches typos instantly, but format alone doesn't tell you a bank branch actually exists or that a GSTIN's checksum is correct. Combine a client-side pre-check with a free API for the authoritative answer.
IFSC โ format check + lookup
An IFSC is 11 characters: 4 letters (bank) + 0 + 6 alphanumerics (branch).
function looksLikeIFSC(v) {
return /^[A-Z]{4}0[A-Z0-9]{6}$/.test(v.toUpperCase());
}
async function lookupIFSC(v) {
v = v.toUpperCase();
if (!looksLikeIFSC(v)) return { ok: false, reason: "bad_format" };
const res = await fetch(`https://api.apibharat.com/v1/ifsc/${v}`);
const json = await res.json();
return json.success
? { ok: true, bank: json.data.bank, branch: json.data.branch, city: json.data.city }
: { ok: false, reason: "not_found" };
}
// lookupIFSC("SBIN0000001") -> { ok:true, bank:"State Bank of India", ... }{
"success": true,
"data": {
"ifsc": "SBIN0000001",
"bank": "State Bank of India",
"branch": "KOLKATA MAIN",
"city": "Kolkata",
"state": "West Bengal",
"micr": "700002021"
},
"message": "IFSC details found"
}GSTIN โ structure + checksum
A GSTIN is 15 characters: 2-digit state code + 10-character PAN + 1 entity digit + Z + 1 checksum character. The API verifies the structure and recomputes the official checksum, then decodes the state, PAN and taxpayer type โ fully offline, no external calls.
function looksLikeGSTIN(v) {
return /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/.test(v.toUpperCase());
}
async function validateGSTIN(v) {
v = v.toUpperCase();
if (v.length !== 15) return { valid: false };
const res = await fetch(`https://api.apibharat.com/v1/gst/validate/${v}`);
const { data } = await res.json();
return data; // { valid, state, pan, entity_type, checksum_valid, ... }
}{
"success": true,
"data": {
"gstin": "27AAPFU0939F1ZV",
"valid": true,
"structure_valid": true,
"checksum_valid": true,
"state_code": "27",
"state": "Maharashtra",
"pan": "AAPFU0939F",
"entity_type": "Firm / Limited Liability Partnership",
"note": "Format & checksum validation only. This does not confirm the GSTIN is registered with the GST department."
},
"message": "GSTIN is valid"
}Good to know
- These checks confirm the number is well-formed and internally consistent โ not that the account or registration is active with the bank/GST department.
- Always uppercase input before validating; users paste lowercase.
- The GSTIN's 4th PAN character reveals the taxpayer type (individual, company, firm, HUF, etc.).
Try it
Test in the browser with the IFSC Finder and GSTIN Validator, or see the IFSC and GST API references.