0

I am unable to do a validation for string sometext.sometext.sometext.sometext.sometext....

I have tried with this regular expression ^[\w]*.{1,}[\w]$ matches the above string but if i give more than one dots consecutively inbetween the text for eg. sometext.sometext.....sometext above regular expression matches this also.

Any help is appreciated.

Thanks in advance.

1 Answer 1

6

{1,} means that there is at least one occurence. If you want exactly one occurence, just use the character as is. Also, you need to escape the dot in your regex, since it stands for "any character" if you don't.

The following should work if you want to allow 1-n non-empty string parts separated by dots:

^\w+(\.\w+)*$
Sign up to request clarification or add additional context in comments.

2 Comments

+1, but you don't really need the square brackets: ^\w+(\.\w+)*$
Oh how ironic, so I made basically the same mistake that I found in mithunsatheesh's answer :D. Edited, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.