javascript - regex to allow string, string followed by numbers, and hyphen -
this question has answer here:
i wanna regex allow following samples
1) abcd 2) abcd123 3) abcd-123 which should not allow
1) 123abcd 2) 123 3) 123-123
you can use regex:
/^[a-z]+-?\d*$/i regex breakup:
^- assert start[a-z]+- match 1 or more alphabets-?- match optional hyphen\d*- match 0 or more digits$- assert end
Comments
Post a Comment