Monday, October 17, 2022

[FIXED] how to get length of integers in PHP ?

Issue

I want to get the length of integer values for validation in PHP. Example: Mobile numbers should be only 10 integer values. It should not be more than 10 or less than 10 and also it should not be included of alphabetic characters.

How can I validate this?


Solution

if (preg_match('/^\d{10}$/', $string)) {
  // pass
} else {
  // fail
}


Answered By - Alex Howansky
Answer Checked By - Robin (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.