Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(isUpiId): Added regex and tests for UPI id validation #2318

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ import isStrongPassword from './lib/isStrongPassword';

import isVAT from './lib/isVAT';

import isUPIId from './lib/isUpiId';

const version = '13.11.0';

const validator = {
Expand Down Expand Up @@ -236,6 +238,7 @@ const validator = {
isLicensePlate,
isVAT,
ibanLocales,
isUPIId,
};

export default validator;
7 changes: 7 additions & 0 deletions src/lib/isUpiId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function isUPIId(upiId) {
// Regular expression pattern for UPI ID validation
const upiPattern = /^[a-zA-Z0-9]+@[a-zA-Z0-9-]+$/;

return upiPattern.test(upiId);
}
export default isUPIId;
74 changes: 26 additions & 48 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14463,54 +14463,32 @@ describe('Validators', () => {
],
});
});
it('should validate mailto URI', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove existing tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the existing test for the format and modified it according to my function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WikiRik can you check I modified the code and fixed the bugs!

test({
validator: 'isMailtoURI',
valid: [
'mailto:?subject=something&[email protected]',
'mailto:?subject=something&[email protected],[email protected],',
'mailto:?subject=something&[email protected]',
'mailto:?subject=something&[email protected],[email protected]',
'mailto:[email protected],[email protected]',
'mailto:[email protected],[email protected]',
'mailto:[email protected]',
'mailto:[email protected]',
'mailto:?subject=something&body=something else',
'mailto:?subject=something&body=something else&[email protected],[email protected]',
'mailto:?subject=something&body=something else&[email protected],[email protected]',
'mailto:?subject=something&body=something else&[email protected]&[email protected],[email protected]',
'mailto:[email protected]',
'mailto:[email protected]?',
'mailto:[email protected]?subject=something',
'mailto:[email protected]?subject=something&[email protected]',
'mailto:[email protected]?subject=something&[email protected],[email protected],',
'mailto:[email protected]?subject=something&[email protected]',
'mailto:[email protected]?subject=something&[email protected],[email protected]',
'mailto:[email protected][email protected],[email protected]',
'mailto:[email protected][email protected],[email protected]',
'mailto:[email protected][email protected]',
'mailto:[email protected][email protected]&',
'mailto:[email protected]?subject=something&body=something else',
'mailto:[email protected]?subject=something&body=something else&[email protected],[email protected]',
'mailto:[email protected]?subject=something&body=something else&[email protected],[email protected]',
'mailto:[email protected]?subject=something&body=something else&[email protected]&[email protected],[email protected]',
'mailto:',
],
invalid: [
'',
'somthing',
'[email protected]',
'mailto:?subject=okay&subject=444',
'mailto:?subject=something&wrong=888',
'mailto:somename@gmail.com',
'mailto:[email protected]?cc=somename@gmail.com',
'mailto:[email protected]?bcc=somename@gmail.com',
'mailto:[email protected]?bcc=somename@gmail.com&bcc',
'mailto:[email protected]?subject=anything&body=nothing&cc=&bcc=&key=',
'mailto:[email protected]?cc=somename',
'mailto:somename',
'mailto:[email protected]?subject=something&body=something else&[email protected]&[email protected],[email protected]&',
'mailto:?subject=something&body=something else&[email protected]&[email protected],[email protected]&',
it('should validate the given UPI address', () => {
test({
validator: 'isUPIId',
valid: [
'john@examplebank',
'sarah@mybank',
'1234567890@yourbank',
'alice@anotherbank',
'jdoe@somewherebank',
'testuser@bank1',
'myupi@bank2',
'upiaccount@bank3',
'anotheruser@bank4',
'jsmith@bank5',
],
invalid: [
'', // Empty string
'missingbankname', // Missing "@" symbol.
'@bankwithspecialcharacters', // Missing username.
'user@bank with spaces', // Spaces in the bank name.
'user@@bank', // Double "@" symbols.
'user&bank', // Special characters in the bank name.
'user@invalid-bank-name-with-dashes', // Invalid characters in bank name.
'user@123bank', // Bank name starting with a number.
'user@bank!', // Exclamation mark in bank name.
'user@',
],
});
});
Expand Down