Home > Software engineering >  PHP regex, prevent numbers to contain dots and commas
PHP regex, prevent numbers to contain dots and commas

Time:07-29

I'm looking for a regex to accept only numbers without dots and commas,

  8500 --> true
  75,001 --> false
  3.500 --> false

I'm trying this regex /[^0-9,.]/ but it doesn't work

Thank you for help

CodePudding user response:

For symfony assets :

@Assert\Regex(pattern="/^[0-9] $/",match=true,message="This field must not contain periods and commas")

CodePudding user response:

Regex: ^\d $

Here is an explanation: https://regex101.com/r/zjaCto/1

Here is php online example: https://onlinephp.io/c/6673a

  • Related