I'd like to know if this regex expression is correct for checking that a string doesn't start with a dot, doesn't end with a dot and contains at least one dot anywhere but not the start or end:
My issue is that I can't figure on how to check if there's 2 dots in a row.
/^([^.])+([.])+.*([^.])$/
It seems you need to use
^[^.]+(?:\.[^.]+)+$
See the regex demo
Details:
^ - start of string[^.]+ - 1+ chars other than a . (so, the first char cannot be .)(?:\.[^.]+)+ - 1 or more (thus, the dot inside a string is obligatory to appear at least once) sequences of:
\. - a dot[^.]+ - 1+ chars other than . (the + quantifier makes a char other than . appear at least once after a dot, thus, making it impossible to match the string with 2 dots on end)$ - end of string.You're close, have a try with:
^[^.]+(?:\.[^.]+){2,}$
It maches strings that have 2 or more dot, but not at the begining or at the end.
If you want one or more dot:
^[^.]+(?:\.[^.]+)+$
If you want one or two dots:
^[^.]+(?:\.[^.]+){1,2}$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With