$mobile = 13427987654; if (preg_match("/^1[3|4|5|8][0-9]d{4,8}$/",$mobile) { $mobile = substr_replace($mobile,'****',3,4); }