File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,15 @@ export class StringValidator extends BaseValidator<string> {
6767 } )
6868 }
6969
70+ equals ( param : string ) : this {
71+ return this . addRule ( {
72+ name : 'equals' ,
73+ test : ( value : string ) => value === param ,
74+ message : 'Must be equal to {param}' ,
75+ params : { param } ,
76+ } )
77+ }
78+
7079 alphanumeric ( ) : this {
7180 return this . addRule ( {
7281 name : 'alphanumeric' ,
Original file line number Diff line number Diff line change @@ -40,6 +40,18 @@ describe('Validation Library', () => {
4040 expect ( validator . test ( 'abc123' ) ) . toBe ( true )
4141 expect ( validator . test ( 'abc-123' ) ) . toBe ( false )
4242 } )
43+
44+ test ( 'equals validation - useful for password confirmation' , ( ) => {
45+ const password = 'mySecurePassword123'
46+ const validator = v . string ( ) . equals ( password )
47+ expect ( validator . test ( password ) ) . toBe ( true )
48+ expect ( validator . test ( 'differentPassword' ) ) . toBe ( false )
49+
50+ // Test with empty strings
51+ const emptyValidator = v . string ( ) . equals ( '' )
52+ expect ( emptyValidator . test ( '' ) ) . toBe ( true )
53+ expect ( emptyValidator . test ( 'not-empty' ) ) . toBe ( false )
54+ } )
4355 } )
4456
4557 describe ( 'Number Validator' , ( ) => {
You can’t perform that action at this time.
0 commit comments