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)
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论