I want a regular expression to test that a string meets the following rules:
- It must not begin with
.. - It must not end with
.. - It must not include special characters like
!@#$%^&*, but can include.. - It must not include two dots
.side by side.
Sample valid input:
na.me(single dot in middle)
Sample invalid input:
.name(begins with dot)name.(ends with dot)na..me(includes two dots side-by-side)$name(special character not allowed in any position)name#(likewise)na#me(likewise)
I believe this should work:
If not in ECMAScript, then replace the
\w‘s with[a-zA-Z_0-9].The approach here is that instead of citing what’s NOT acceptable, it’s easier to cite what’s acceptable.
Translation of the expression is: