Reputation: 2070
I need a regexp works like this: it only accepts strings made up of all numbers or all letters (for example: "111111111111","aaaaaaaa", not "aaaaa11111").
I tried this
/(^[0-9]+$) | (^[a-z]$)/.test('111111111111')
, not working though.
What's the right way to do it ?
Upvotes: 0
Views: 44
Reputation: 7091
First, remove the spaces, and second, your [a-z]
is lacking a +
. So, the working version is:
/(^[0-9]+$)|(^[a-z]+$)/
Upvotes: 1