[英]PHP Simple PCRE regex to only allow 1 dot or none?
I'm trying to create a regex for alias validation: 我正在尝试创建用于别名验证的正则表达式:
And I'm allowing letters, numbers and 1 dot. 我允许使用字母,数字和1个点。
I have done the following: 我已经完成以下工作:
/^[a-z0-9\\.]+$/i
However it allows more then 1 dot? 但是,它允许多于1点吗?
This should do it: 应该这样做:
/^(?:\.[a-z0-9]+|[a-z0-9]+(?:\.[a-z0-9]*)?)$/i
This allows the string to either: 这使字符串可以:
try this: 尝试这个:
^(?:[a-z0-9]+\.?[a-z0-9]*|[a-z0-9]*\.?[a-z0-9]+)$
places the dot in the center, then allows it to be surrounded on either side. 将圆点放在中心,然后将其围绕在任一侧。
我认为在这种情况下,允许将点作为第一个或最后一个字符不是一个好主意:
/^[a-z0-9]+\.?[a-z0-9]+$/i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.