简体   繁体   中英

How to validate a string which can contain numbers spaces, + and - using regex php

I want to validate phone numbers like follows using php.

+009411774132482 011 2560-205

试试这个'/^\\+?[0-9 \\-]+$/'

This should do it...

preg_match('/^\+?[\d -]+\z/', $str);

CodePad .

It will allow...

  • An optional preceding + .
  • More than one of digits ( 0-9 ), space and - . If you want a minimum amount, swap the + with {9,} .
  • Does not allow a trailing \\n .

试试这个正则表达式:

^[\d\s+-]+$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM