How can I write a regular expression in javascript that only allows users to write this:
abc.def, abc-def or abc
So basically match a pattern that only contains letters (only lowercase [a-z]) and a . or -. But does not match - or . at the beginning or end of string or multiple times(only one . or - per string)
So not allowing them to do:
..... abc...abc abc.abc.... abc----.... ...abc.abc .abc -abc etc.
Regex would be:
/^[a-z]+([\.\-]?[a-z]+)?$/JavaScript:
See and test the code here.