I want to upgrade my regex to let user write .
or number but not alone and not write .
in last of word
Example: I want to write
hello to web 2.0
or hello farah.开发者_如何学Pythonnor
but not hello word.
and not .....................
or 213123213123123
Here is my regex
preg_match('#^[a-z0-9. ]+$#i',$text)
You're nearly there:
preg_match('#^[a-z0-9. ]+(?<!\.)$#i',$text)
The negative lookbehind makes sure that the string doesn't end in .
(which it also does if it consists of .
alone, so that condition is caught, too).
EDIT:
Now that you also want to disallow "digits only", you also need a lookahead assertion:
preg_match('#^(?![0-9]*$)[a-z0-9. ]+(?<!\.)$#i',$text)
精彩评论