开发者

regular expression for some special charaters and number in php

开发者 https://www.devze.com 2023-03-27 05:43 出处:网络
I am looking for a php regex that can contain only , and - chracters. in short i would like a regex that can match the following:

I am looking for a php regex that can contain only , and - chracters.

in short i would like a regex that can match the following:

* may contain number
* may contain space
* may contain , -

i am making a php script to check if a certain string have the above or not, like a validation check. i hav开发者_运维百科e tried with this

^([\[\]=,{\}\0-9_-]+)$

but not working. please someone help me.


The - literal must be the first or last character in character classes. Otherwise, it's a range indicator:

^[0-9 ,-]+$

(Not sure though why you add = and other stuff.)


preg_match("#-?\d+(,\d+)?#", "-1,2", $match);


Try this regular expression:

^[\d\s,-]*$


Use this:

^([\ ,0-9-]*)$

I offer you using this site to see what your regex expose.

0

精彩评论

暂无评论...
验证码 换一张
取 消