-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Swarga-codes
wants to merge
6
commits into
validatorjs:master
Choose a base branch
from
Swarga-codes:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad60916
feat(isUpiId): added the regex and function that validates a given UP…
Swarga-codes 30375b1
feat(isUPIId): added tests for upi validation
Swarga-codes 86c74ca
fix: formatted code as per eslint standards
Swarga-codes 63e2a28
fix: formatted code as per eslint standards
Swarga-codes 530c144
fix: modified the code for edge cases
Swarga-codes 3942950
fix:modified logic for UPIs starting with numbers
Swarga-codes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14463,54 +14463,32 @@ describe('Validators', () => { | |
], | ||
}); | ||
}); | ||
it('should validate mailto URI', () => { | ||
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@', | ||
], | ||
}); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!