regular expression for some special charaters and number in php
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.
精彩评论