sq2
sq2

Reputation: 595

PHP Regex Allow numbers only with a specific length

I am trying to create a preg_match test to allow numbers only. Definitely cannot use is_numeric or any variants.

Is this as safe as I can get?

/^\d*$/

And additionally, how would I set a min max range, for example check the number is between 6 and 10 digits?

Upvotes: 0

Views: 8481

Answers (1)

Martin Ender
Martin Ender

Reputation: 44259

Well yeah, that's pretty safe. The regex does exactly that... allow only digits.

To specify a certain amount, here is the syntax:

/^\d{6,10}$/

However, since this is a very basic problem, you should probably check out this site.

Upvotes: 2

Related Questions