I am checking input string which can have only digits and optional single forward slash that should not be at start or end position.
123456789 // valid
3221345431 // valid
23243245/34 // valid
454556/322 // valid
45435//564 // invalid as more than one /
454354356/ // invalid as / is at end position
/454354354 // invalid as / is not start position
I tried using RegExp
but its not giving me intended results.
> re = RegExp('\\d+\/?\\d+')
/\d+\/?\d+/
> re.test('12791771/21')
true // This is correct
> re.test('477199337932')
true // This is correct
> re.test('12200977/')
true // This is wrong because / is at end position
> re.test('122009//77')
true // This is wrong because more than one /
> re.test('/12200977')
true // This is wrong because / is at start position
What I am doing wrong so not getting false
in last three cases?