Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Validator | Description
**isSemVer(str)** | check if the string is a Semantic Versioning Specification (SemVer).
**isSurrogatePair(str)** | check if the string contains any surrogate pairs chars.
**isUppercase(str)** | check if the string is uppercase.
**isUPI(str)** | check id the string is UPI
**isSlug(str)** | check if the string is of type slug.
**isStrongPassword(str [, options])** | check if the string can be considered a strong password or not. Allows for custom requirements or scoring rules. If `returnScore` is true, then the function returns an integer score for the password rather than a boolean.<br/>Default options: <br/>`{ minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1, returnScore: false, pointsPerUnique: 1, pointsPerRepeat: 0.5, pointsForContainingLower: 10, pointsForContainingUpper: 10, pointsForContainingNumber: 10, pointsForContainingSymbol: 10 }`
**isTime(str [, options])** | check if the string is a valid time e.g. [`23:01:59`, new Date().toLocaleTimeString()].<br/><br/> `options` is an object which can contain the keys `hourFormat` or `mode`.<br/><br/>`hourFormat` is a key and defaults to `'hour24'`.<br/><br/>`mode` is a key and defaults to `'default'`. <br/><br/>`hourFomat` can contain the values `'hour12'` or `'hour24'`, `'hour24'` will validate hours in 24 format and `'hour12'` will validate hours in 12 format. <br/><br/>`mode` can contain the values `'default'` or `'withSeconds'`, `'default'` will validate `HH:MM` format, `'withSeconds'` will validate the `HH:MM:SS` format.
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import isPassportNumber from './lib/isPassportNumber';
import isPort from './lib/isPort';
import isLowercase from './lib/isLowercase';
import isUppercase from './lib/isUppercase';
import isUPI from './lib/isUPI';

import isIMEI from './lib/isIMEI';

Expand Down Expand Up @@ -155,6 +156,7 @@ const validator = {
isPort,
isLowercase,
isUppercase,
isUPI,
isAscii,
isFullWidth,
isHalfWidth,
Expand Down
8 changes: 8 additions & 0 deletions src/lib/isUPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import assertString from './util/assertString';

const upiRegex = /^[a-zA-Z0-9]+@[a-zA-Z]+$/;

export default function isUPI(str) {
assertString(str);
return upiRegex.test(str);
}
20 changes: 20 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4033,6 +4033,26 @@ describe('Validators', () => {
});
});

it('should validate upi strings', () => {
test({
validator: 'isUPI',
valid: [
'test@upi',
'test@paytm',
'test@ybl',
'test@okhdfcbank',
],
invalid: [
'test@',
'1224',
'@ss2',
'test@upi@',
'test@123',
'test@1upi',
],
});
});

it('should validate integers', () => {
test({
validator: 'isInt',
Expand Down