Phone number validation in PHP

后端 未结 3 846
渐次进展
渐次进展 2021-01-23 07:21

I need to validate phone number in PHP. I have made following regex, but I also need to it to accept numbers starting with plus char, how can I do that?

^[0-9]$         


        
3条回答
  •  清酒与你
    2021-01-23 08:07

    Try this:

    /^[\+]?([0-9]*)\s*\(?\s*([0-9]{3})?\s*\)?[\s\-\.]*([0-9]{3})[\s\-\.]*([0-9]{4})[a-zA-Z\s\,\.]*[x\#]*[a-zA-Z\.\s]*([\d]*)/
    

    will match:

    +1 ( 111)111-1111, #111

    111-111-1111

    (111)111-1111 x 1

    111.111.1111x1

    etc.

提交回复
热议问题