I wanna regex which will allow the following samples
1) abcd
2) abcd123
3) abcd-123
which should not allow
1) 123abcd
2) 123
3) 123-123
I wanna regex which will allow the following samples
1) abcd
2) abcd123
3) abcd-123
which should not allow
1) 123abcd
2) 123
3) 123-123
You can use this regex:
/^[a-z]+-?\d*$/i
RegEx Breakup:
^ - Assert start[a-z]+ - Match 1 or more alphabets-? - Match an optional hyphen\d* - Match 0 or more digits$ - Assert end