-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: :: Added a pattern regex validation
- Loading branch information
Showing
6 changed files
with
28 additions
and
3 deletions.
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
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,8 @@ | ||
export default { | ||
name: 'pattern', | ||
message: 'Please enter a value following the pattern /{0}/', | ||
paramType: String, | ||
fn: (value, element, param) => { | ||
return new RegExp(param).test(value); | ||
}, | ||
}; |
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,13 @@ | ||
import Pattern from '../../src/pattern'; | ||
|
||
describe('Pattern Validation', () => { | ||
test('Test: Should pass when typed only numbers', () => { | ||
const isValid = Pattern.fn('250', null, '^[0-9]+$'); | ||
expect(isValid).toBe(true); | ||
}); | ||
|
||
test('Test: Should fail when typed letters and number', () => { | ||
const isValid = Pattern.fn('ws4', null, '^[0-9]+$'); | ||
expect(isValid).toBe(false); | ||
}); | ||
}); |