Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Sanitizer | Description
**trim(input [, chars])** | trim characters (whitespace by default) from both sides of the input.
**unescape(input)** | replace HTML encoded entities with `<`, `>`, `&`, `'`, `"`, `` ` ``, `\` and `/`.
**whitelist(input, chars)** | remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will need to escape some chars, e.g. `whitelist(input, '\\[\\]')`.

**isPAN(str)** | check if the string is a valid Indian PAN number.
### XSS Sanitization

XSS sanitization was removed from the library in [2d5d6999](https://github.com/validatorjs/validator.js/commit/2d5d6999541add350fb396ef02dc42ca3215049e).
Expand Down
20 changes: 10 additions & 10 deletions build-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import babelPresetEnv from "@babel/preset-env";
import pkg from "./package.json";

rollup({
entry: "src/index.js",
input: "src/index.js",
plugins: [
babel({
presets: [[babelPresetEnv, { modules: false }]],
Expand All @@ -16,15 +16,15 @@ rollup({
})
.then((bundle) =>
bundle.write({
dest: "validator.js",
format: "umd",
moduleName: pkg.name,
banner: `/*!\n${String(fs.readFileSync("./LICENSE"))
.trim()
.split("\n")
.map((l) => ` * ${l}`)
.join("\n")}\n */`,
})
file: "validator.js",
format: "umd",
name: pkg.name,
banner: `/*!\n${String(fs.readFileSync("./LICENSE"))
.trim()
.split("\n")
.map((l) => ` * ${l}`)
.join("\n")}\n */`,
})
)
.catch((e) => {
process.stderr.write(`${e.message}\n`);
Expand Down
6 changes: 0 additions & 6 deletions jsconfig.json

This file was deleted.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"npm-run-all": "^4.1.5",
"nyc": "^14.1.0",
"rimraf": "^3.0.0",
"rollup": "^0.47.0",
"rollup-plugin-babel": "^4.0.1",
"rollup": "^2.80.0",
"rollup-plugin-babel": "^4.4.0",
"timezone-mock": "^1.3.6",
"uglify-js": "^3.0.19"
},
Expand All @@ -72,5 +72,8 @@
"engines": {
"node": ">= 0.10"
},
"license": "MIT"
"license": "MIT",
"dependencies": {
"validator": "^13.15.35"
}
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import isLicensePlate from './lib/isLicensePlate';
import isStrongPassword from './lib/isStrongPassword';

import isVAT from './lib/isVAT';
import isPAN from './lib/isPAN';

const version = '13.15.35';

Expand Down Expand Up @@ -244,6 +245,7 @@ const validator = {
isTime,
isLicensePlate,
isVAT,
isPAN,
ibanLocales,
};

Expand Down
4 changes: 4 additions & 0 deletions src/lib/isPAN.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function isPAN(str) {
const panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]$/;
return panRegex.test(str);
}
24 changes: 24 additions & 0 deletions test/validators/isPAN.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import validator from '../../src/index';
import assert from 'assert';

Check failure on line 2 in test/validators/isPAN.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Absolute imports should come before relative imports

Check failure on line 2 in test/validators/isPAN.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Absolute imports should come before relative imports

Check failure on line 2 in test/validators/isPAN.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Absolute imports should come before relative imports

Check failure on line 2 in test/validators/isPAN.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Absolute imports should come before relative imports

describe('isPAN', () => {
it('valid PAN', () => {
assert.strictEqual(validator.isPAN('ABCDE1234F'), true);
});

it('invalid length', () => {
assert.strictEqual(validator.isPAN('ABCDE123F'), false);
});

it('lowercase should fail', () => {
assert.strictEqual(validator.isPAN('abcde1234f'), false);
});

it('wrong format', () => {
assert.strictEqual(validator.isPAN('1234ABCDE1'), false);
});

it('empty string', () => {
assert.strictEqual(validator.isPAN(''), false);
});
});
Loading